diff options
| author | Ben Beltran <ben@nsovocal.com> | 2015-07-10 11:12:25 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2015-07-10 11:12:25 -0500 |
| commit | 24c7594d62d8d7fbbcdb64b11ce4adc5d8e6991a (patch) | |
| tree | ded312222bb108923da1820ba40b04d710d20e5b /atom/packages/relative-line-numbers | |
| parent | eb786e82d170e2abc351a432ade616d6ecdeeb6b (diff) | |
Adds atom
Diffstat (limited to 'atom/packages/relative-line-numbers')
7 files changed, 159 insertions, 0 deletions
diff --git a/atom/packages/relative-line-numbers/.npmignore b/atom/packages/relative-line-numbers/.npmignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/atom/packages/relative-line-numbers/.npmignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/atom/packages/relative-line-numbers/CHANGELOG.md b/atom/packages/relative-line-numbers/CHANGELOG.md new file mode 100644 index 0000000..fe9b511 --- /dev/null +++ b/atom/packages/relative-line-numbers/CHANGELOG.md @@ -0,0 +1,7 @@ +## 0.1.3 +* Clean up + +## 0.1.2 +* Relative line numbers are now loaded by default. + +## 0.1.0 - Initial release diff --git a/atom/packages/relative-line-numbers/LICENSE.md b/atom/packages/relative-line-numbers/LICENSE.md new file mode 100644 index 0000000..d343bd8 --- /dev/null +++ b/atom/packages/relative-line-numbers/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2015 Robert van Steen + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/atom/packages/relative-line-numbers/README.md b/atom/packages/relative-line-numbers/README.md new file mode 100644 index 0000000..1ada251 --- /dev/null +++ b/atom/packages/relative-line-numbers/README.md @@ -0,0 +1,4 @@ +# relative-line-numbers package + +Replaces the regular line numbers with relative numbers. +Also has an option to show the true number on the current line. diff --git a/atom/packages/relative-line-numbers/lib/line-number-view.coffee b/atom/packages/relative-line-numbers/lib/line-number-view.coffee new file mode 100644 index 0000000..6346a3c --- /dev/null +++ b/atom/packages/relative-line-numbers/lib/line-number-view.coffee @@ -0,0 +1,61 @@ +{CompositeDisposable} = require 'atom' + +module.exports = +class LineNumberView + constructor: (@editor) -> + @subscriptions = new CompositeDisposable() + @editorView = atom.views.getView(@editor) + @trueNumberCurrentLine = atom.config.get('relative-line-numbers.trueNumberCurrentLine') + @showNormalLineNumbers = atom.config.get('relative-line-numbers.showNormalLineNumbers') + + # Subscribe for when the line numbers should be updated. + @subscriptions.add(@editor.onDidChangeCursorPosition(@_update)) + @subscriptions.add(@editor.onDidStopChanging(@_update)) + + # Subscribe to when the true number on current line config is modified. + @subscriptions.add atom.config.onDidChange 'relative-line-numbers.trueNumberCurrentLine', => + @trueNumberCurrentLine = atom.config.get('relative-line-numbers.trueNumberCurrentLine') + @_update() + + # Subscribe to when the show normal line numbers config is modified. + @subscriptions.add atom.config.onDidChange 'relative-line-numbers.showNormalLineNumbers', => + @showNormalLineNumbers = atom.config.get('relative-line-numbers.showNormalLineNumbers') + @_update() + + # Dispose the subscriptions when the editor is destroyed. + @subscriptions.add @editor.onDidDestroy => + @subscriptions.dispose() + + @_update() + + _spacer: (totalLines, currentIndex) -> + Array(totalLines.toString().length - currentIndex.toString().length + 1).join ' ' + + # Update the line numbers on the editor + _update: () => + totalLines = @editor.getLineCount() + currentLineNumber = @editor.getCursorScreenPosition().row + 1 + lineNumberElements = @editorView.rootElement?.querySelectorAll('.line-number') + + index = @_index(totalLines, currentLineNumber) + + for lineNumberElement in lineNumberElements + row = lineNumberElement.getAttribute('data-buffer-row') + relative = index[row] or = 0 + normalLineNumbers = '' + if @showNormalLineNumbers + humanRow = parseInt(row) + 1 + normalLineNumbers = humanRow + @_spacer(totalLines, humanRow) + " " + lineNumberElement.innerHTML = "#{normalLineNumbers}#{relative}<div class=\"icon-right\"></div>" + + # Return a lookup array with the relative line numbers + _index: (totalLines, currentLineNumber) -> + for line in [0...totalLines] + lineNumber = (Math.abs(currentLineNumber - (line + 1))) + if @trueNumberCurrentLine and lineNumber == 0 + if @showNormalLineNumbers + '•' + else + currentLineNumber + else + lineNumber diff --git a/atom/packages/relative-line-numbers/lib/relative-line-numbers.coffee b/atom/packages/relative-line-numbers/lib/relative-line-numbers.coffee new file mode 100644 index 0000000..34fd190 --- /dev/null +++ b/atom/packages/relative-line-numbers/lib/relative-line-numbers.coffee @@ -0,0 +1,24 @@ +LineNumberView = require './line-number-view' + +module.exports = + # Config schema + config: + trueNumberCurrentLine: + type: 'boolean' + default: true + description: 'Show the true number on the current line' + showNormalLineNumbers: + type: 'boolean' + default: true + description: 'Show normal line numbers' + + configDefaults: + trueNumberCurrentLine: true + showNormalLineNumbers: true + + activate: (state) -> + console.log('Activiating relative line numbers.'); + atom.workspace.observeTextEditors (editor) -> + new LineNumberView(editor) + + deactive: () -> diff --git a/atom/packages/relative-line-numbers/package.json b/atom/packages/relative-line-numbers/package.json new file mode 100644 index 0000000..c367c08 --- /dev/null +++ b/atom/packages/relative-line-numbers/package.json @@ -0,0 +1,40 @@ +{ + "name": "relative-line-numbers", + "main": "./lib/relative-line-numbers", + "version": "0.1.5", + "description": "Relative line numbers for Atom", + "repository": { + "type": "git", + "url": "https://github.com/rovansteen/atom-relative-line-numbers" + }, + "license": "MIT", + "activationEvents": [], + "engines": { + "atom": ">=0.174.0 <2.0.0" + }, + "dependencies": {}, + "readme": "# relative-line-numbers package\n\nReplaces the regular line numbers with relative numbers.\nAlso has an option to show the true number on the current line.\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/rovansteen/atom-relative-line-numbers/issues" + }, + "homepage": "https://github.com/rovansteen/atom-relative-line-numbers", + "_id": "relative-line-numbers@0.1.5", + "_shasum": "0ac976da8ee9a717118a60ade739820b9f0af0b4", + "_resolved": "file:../d-11567-50205-nqln2s/package.tgz", + "_from": "../d-11567-50205-nqln2s/package.tgz", + "_atomModuleCache": { + "version": 1, + "dependencies": [], + "extensions": { + ".coffee": [ + "lib/line-number-view.coffee", + "lib/relative-line-numbers.coffee" + ], + ".json": [ + "package.json" + ] + }, + "folders": [] + } +}
\ No newline at end of file |