├── .eslintrc.json
├── .gitignore
├── .travis.yml
├── LICENSE.md
├── README.md
├── caps
├── mode-letter.gif
├── mode-words-starting.gif
└── mode-words.gif
├── keymaps
└── easy-motion-redux.cson
├── lib
├── main.js
└── views
│ ├── input.js
│ ├── letter.js
│ └── markers.js
├── package.json
├── styles
└── easy-motion-redux.less
└── yarn.lock
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true,
4 | "es6": true
5 | },
6 | "parserOptions": {
7 | "ecmaVersion": 6,
8 | "sourceType": "module",
9 | "ecmaFeatures": {
10 | "arrowFunctions": true,
11 | "blockBindings": true,
12 | "classes": true,
13 | "defaultParameters": true,
14 | "destructuring": true,
15 | "forOf": true,
16 | "generators": true,
17 | "modules": true,
18 | "objectLiteralComputedProperties": true,
19 | "objectLiteralDuplicateProperties": true,
20 | "objectLiteralShorthandMethods": true,
21 | "objectLiteralShorthandProperties": true,
22 | "regexUFlag": true,
23 | "regexYFlag": true,
24 | "restParams": true,
25 | "spread": true,
26 | "superInFunctions": true,
27 | "templateStrings": true,
28 | "unicodeCodePointEscapes": true,
29 | "globalReturn": true
30 | }
31 | },
32 | "rules": {
33 | "comma-dangle": [ 2, "never" ],
34 | "no-console": 1,
35 | "no-constant-condition": 2,
36 | "no-control-regex": 2,
37 | "no-debugger": 1,
38 | "no-dupe-keys": 2,
39 | "no-duplicate-case": 2,
40 | "no-empty-character-class": 2,
41 | "no-empty": 2,
42 | "no-extra-boolean-cast": 2,
43 | "no-extra-semi": 2,
44 | "no-func-assign": 2,
45 | "no-inner-declarations": 2,
46 | "no-invalid-regexp": 2,
47 | "no-irregular-whitespace": 2,
48 | "no-negated-in-lhs": 2,
49 | "no-unreachable": 2,
50 | "use-isnan": 2,
51 | "valid-typeof": 2,
52 |
53 | "accessor-pairs": 2,
54 | "block-scoped-var": 2,
55 | "curly": 2,
56 | "dot-location": [ 2, "property" ],
57 | "dot-notation": 2,
58 | "eqeqeq": [ 2, "smart" ],
59 | "no-alert": 1,
60 | "no-caller": 2,
61 | "no-case-declarations": 2,
62 | "no-div-regex": 1,
63 | "no-else-return": 2,
64 | "no-eval": 2,
65 | "no-extend-native": 2,
66 | "no-extra-bind": 2,
67 | "no-fallthrough": 2,
68 | "no-floating-decimal": 2,
69 | "no-implied-eval": 2,
70 | "no-iterator": 2,
71 | "no-labels": 2,
72 | "no-lone-blocks": 2,
73 | "no-loop-func": 2,
74 | "no-multi-spaces": 2,
75 | "no-multi-str": 2,
76 | "no-native-reassign": 2,
77 | "no-new-func": 2,
78 | "no-new-wrappers": 2,
79 | "no-new": 2,
80 | "no-octal-escape": 2,
81 | "no-octal": 2,
82 | "no-param-reassign": 2,
83 | "no-proto": 2,
84 | "no-redeclare": 2,
85 | "no-return-assign": 2,
86 | "no-self-compare": 2,
87 | "no-throw-literal": 2,
88 | "no-unused-expressions": [ 2, { "allowShortCircuit": true } ],
89 | "no-useless-call": 2,
90 | "no-useless-concat": 2,
91 | "no-void": 2,
92 | "no-warning-comments": 1,
93 | "no-with": 2,
94 | "radix": [ 2, "as-needed" ],
95 | "vars-on-top": 2,
96 | "wrap-iife": [ 2, "inside" ],
97 | "yoda": 2,
98 |
99 | "strict": [ 2, "function" ],
100 |
101 | "no-catch-shadow": 2,
102 | "no-delete-var": 2,
103 | "no-shadow-restricted-names": 2,
104 | "no-shadow": 2,
105 | "no-undef-init": 2,
106 | "no-unused-vars": 2,
107 | "no-use-before-define": 2,
108 |
109 | "global-require": 2,
110 | "handle-callback-err": 1,
111 | "no-new-require": 2,
112 |
113 | "array-bracket-spacing": [ 2, "always" ],
114 | "block-spacing": [ 2, "always" ],
115 | "brace-style": [ 2, "1tbs", { "allowSingleLine": false } ],
116 | "comma-spacing": [ 2, { "before": false, "after": true } ],
117 | "comma-style": [ 2, "last" ],
118 | "computed-property-spacing": [ 2, "always" ],
119 | "consistent-this": [ 2, "self" ],
120 | "eol-last": 2,
121 | "func-style": [ 2, "expression" ],
122 | "indent": [ 2, 4, { "SwitchCase": 1 } ],
123 | "key-spacing": [ 2, { "beforeColon": false, "afterColon": true } ],
124 | "keyword-spacing": [ 2, { "before": true, "after": true, "overrides": {} } ],
125 | "new-cap": [ 2, { "capIsNewExceptions": [ "ObjectId" ] } ],
126 | "new-parens": 2,
127 | "newline-after-var": [ 2, "always" ],
128 | "no-array-constructor": 2,
129 | "no-bitwise": 2,
130 | "no-continue": 2,
131 | "no-lonely-if": 2,
132 | "no-mixed-spaces-and-tabs": 2,
133 | "no-multiple-empty-lines": [ 2, { "max": 2, "maxEOF": 1 } ],
134 | "no-nested-ternary": 2,
135 | "no-new-object": 2,
136 | "no-spaced-func": 2,
137 | "no-trailing-spaces": [ 2, { "skipBlankLines": true } ],
138 | "no-unneeded-ternary": 2,
139 | "object-curly-spacing": [ 2, "always" ],
140 | "one-var": [ 2, "always" ],
141 | "operator-linebreak": [ 2, "none" ],
142 | "quote-props": [ 2, "always" ],
143 | "quotes": [ 2, "double", "avoid-escape" ],
144 | "semi": [ 2, "always" ],
145 | "space-before-blocks": [ 2, "always" ],
146 | "space-before-function-paren": [ 2, "never" ],
147 | "space-in-parens": [ 2, "always" ],
148 | "space-infix-ops": 2,
149 | "space-unary-ops": [ 2, { "words": true, "nonwords": false } ],
150 | "spaced-comment": [ 2, "always" ],
151 |
152 | "arrow-parens": [ 2, "always" ],
153 | "arrow-spacing": 2,
154 | "constructor-super": 2,
155 | "generator-star-spacing": [ 2, { "before": true, "after": false } ],
156 | "no-confusing-arrow": 1,
157 | "no-class-assign": 2,
158 | "no-const-assign": 2,
159 | "no-dupe-class-members": 2,
160 | "no-this-before-super": 2,
161 | "no-var": 2,
162 | "prefer-arrow-callback": 1,
163 | "prefer-spread": 1,
164 | "prefer-template": 1,
165 | "require-yield": 2
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | npm-debug.log
3 | node_modules
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ### Project specific config ###
2 | language: generic
3 |
4 | env:
5 | global:
6 | - APM_TEST_PACKAGES=""
7 | - ATOM_LINT_WITH_BUNDLED_NODE="true"
8 |
9 | matrix:
10 | - ATOM_CHANNEL=stable
11 | - ATOM_CHANNEL=beta
12 |
13 | os:
14 | - linux
15 | - osx
16 |
17 | ### Generic setup follows ###
18 | script:
19 | - curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh
20 | - chmod u+x build-package.sh
21 | - ./build-package.sh
22 |
23 | notifications:
24 | email:
25 | on_success: never
26 | on_failure: change
27 |
28 | branches:
29 | only:
30 | - master
31 |
32 | git:
33 | depth: 10
34 |
35 | sudo: false
36 |
37 | dist: trusty
38 |
39 | addons:
40 | apt:
41 | packages:
42 | - build-essential
43 | - fakeroot
44 | - git
45 | - libsecret-1-dev
46 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 Leny & Adrian Budau
2 |
3 | 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:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | 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.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # atom easy-motion (redux) package
2 |
3 | [](https://travis-ci.org/leny/atom-easy-motion-redux)
4 |
5 | > MovementSpeed++. Jump to any word in your current view super fast.
6 |
7 | * * *
8 |
9 | **Note:** this package is a partial rewrite of the great [easy-motion package](https://github.com/adrian-budau/easy-motion) from Adrian Budau.
10 |
11 | The original package seems dead and, with the deprecation of the atom API pre-1.0, it's sad that we can't use easy-motion in atom anymore. So, i rewrite the package, waiting for news from Adrian.
12 |
13 | * * *
14 |
15 | Check out that repository to better understand what this plugin does.
16 |
17 | ## Modes
18 |
19 | By default the characters used for markers are **ABC....Z**. You can replace this if you want, also from settings.
20 |
21 | ### Jump to words
22 |
23 | **Command:** `easy-motion-redux:words`
24 | Jump to words.
25 |
26 |
27 |
28 | #### Select to words
29 |
30 | **Command:** `easy-motion-redux:words-select`
31 | Select from current cursor position to word.
32 |
33 | ### Jump to letter
34 |
35 | **Command:** `easy-motion-redux:letter`
36 | Jump to given letter.
37 |
38 |
39 |
40 | #### Select to letter
41 |
42 | **Command:** `easy-motion-redux:letter-select`
43 | Select from current cursor position to given letter.
44 |
45 | ### Jump to words starting by letter
46 |
47 | **Command:** `easy-motion-redux:words_starting`
48 | Jump to words starting by given letter.
49 |
50 |
51 |
52 | #### Select to words starting by letter
53 |
54 | **Command:** `easy-motion-redux:words_starting-select`
55 | Select from current cursor position to words starting by given letter.
56 |
57 | ### Jump to lines
58 |
59 | **Command:** `easy-motion-redux:lines`
60 | Jump to lines.
61 |
62 | #### Select to lines
63 |
64 | **Command:** `easy-motion-redux:lines-select`
65 | Select from current cursor position to line.
66 |
67 | ## Keybindings
68 |
69 | With the success of Atom, it's really difficult to choose keybindings that will not enter in conflict whit anyone else's packages, so I have removed the default keystrokes and let the keymap empty to let you set your own keybindings.
70 |
--------------------------------------------------------------------------------
/caps/mode-letter.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leny/atom-easy-motion-redux/596b9cf73ab1dad5732602f701727885d3d6083f/caps/mode-letter.gif
--------------------------------------------------------------------------------
/caps/mode-words-starting.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leny/atom-easy-motion-redux/596b9cf73ab1dad5732602f701727885d3d6083f/caps/mode-words-starting.gif
--------------------------------------------------------------------------------
/caps/mode-words.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leny/atom-easy-motion-redux/596b9cf73ab1dad5732602f701727885d3d6083f/caps/mode-words.gif
--------------------------------------------------------------------------------
/keymaps/easy-motion-redux.cson:
--------------------------------------------------------------------------------
1 | # With the success of Atom, it's really difficult to choose keybindings that
2 | # will not enter in conflict whit anyone else's packages, so I let this file
3 | # empty to set your own keybindings.
4 | # For you informations, here's an exemple of my keybindings for easy-motion-redux
5 |
6 | # ".platform-darwin atom-text-editor:not([mini])":
7 | # "cmd-shift-e": "easy-motion-redux:start"
8 | #
9 | # ".platform-win32 atom-text-editor:not([mini]), .platform-linux atom-text-editor:not([mini])":
10 | # "ctrl-shift-e": "easy-motion-redux:start"
11 |
--------------------------------------------------------------------------------
/lib/main.js:
--------------------------------------------------------------------------------
1 | "use babel";
2 |
3 | import { CompositeDisposable } from "atom";
4 | import InputView from "./views/input";
5 |
6 | let oConfig,
7 | fActivate,
8 | fDeactivate,
9 | oDisposables,
10 | _fStart;
11 |
12 | oConfig = {
13 | "replaceCharacters": {
14 | "type": "string",
15 | "default": "ASDFJKLGHQWERTYUIOPZXCVBNM"
16 | }
17 | };
18 |
19 | _fStart = function( sMode, bSelect ) {
20 | let oInput = new InputView( atom.workspace.getActiveTextEditor(), sMode, bSelect ),
21 | oPanel;
22 |
23 | oPanel = atom.workspace.addBottomPanel( {
24 | "item": oInput
25 | } );
26 |
27 | oInput.resetPositions();
28 | oInput.panel = oPanel;
29 |
30 | if ( oInput.hasPositions() ) {
31 | oInput.focus();
32 | } else {
33 | oInput.remove();
34 | oPanel.destroy();
35 | }
36 | };
37 |
38 | fActivate = function() {
39 | oDisposables && oDisposables.dispose();
40 | oDisposables = new CompositeDisposable();
41 |
42 | oDisposables.add( atom.commands.add( "atom-text-editor:not([mini])", {
43 | "easy-motion-redux:words": () => {
44 | _fStart( InputView.MODE_WORDS );
45 | },
46 | "easy-motion-redux:letter": () => {
47 | _fStart( InputView.MODE_LETTER );
48 | },
49 | "easy-motion-redux:words_starting": () => {
50 | _fStart( InputView.MODE_WORDS_STARTING );
51 | },
52 | "easy-motion-redux:lines": () => {
53 | _fStart( InputView.MODE_LINES );
54 | },
55 | "easy-motion-redux:words-select": () => {
56 | _fStart( InputView.MODE_WORDS, true );
57 | },
58 | "easy-motion-redux:letter-select": () => {
59 | _fStart( InputView.MODE_LETTER, true );
60 | },
61 | "easy-motion-redux:words_starting-select": () => {
62 | _fStart( InputView.MODE_WORDS_STARTING, true );
63 | },
64 | "easy-motion-redux:lines-select": () => {
65 | _fStart( InputView.MODE_LINES, true );
66 | }
67 | } ) );
68 | };
69 |
70 | fDeactivate = function() {
71 | oDisposables && oDisposables.dispose();
72 | };
73 |
74 | export {
75 | oConfig as config,
76 | fActivate as activate,
77 | fDeactivate as deactivate
78 | };
79 |
--------------------------------------------------------------------------------
/lib/views/input.js:
--------------------------------------------------------------------------------
1 | "use babel";
2 |
3 | /* eslint-disable no-loop-func, no-bitwise, no-continue */
4 |
5 | import { View, TextEditorView } from "atom-space-pen-views";
6 | import { CompositeDisposable } from "atom";
7 | import _ from "underscore-plus";
8 | import Markers from "./markers";
9 |
10 | class InputView extends View {
11 | static content() {
12 | return this.div( {
13 | "class": "easy-motion-redux-input"
14 | }, () => {
15 | this.div( {
16 | "class": "editor-container",
17 | "outlet": "editorContainer"
18 | } );
19 | return this.subview( "editorInput", new TextEditorView( {
20 | "mini": true,
21 | "placeholderText": "EasyMotion"
22 | } ) );
23 | } );
24 | }
25 |
26 | constructor( oRefTextEditor, sMode, bSelect ) {
27 | super( oRefTextEditor, sMode, bSelect );
28 | }
29 |
30 | initialize( oRefTextEditor, sMode, bSelect ) {
31 | this.sMode = sMode;
32 | this.bSelect = bSelect;
33 | this.aPositions = [];
34 | this.sLetter = null;
35 | this.oRefTextEditor = oRefTextEditor;
36 |
37 | this.updatePlaceholder();
38 |
39 | this.subscriptions = new CompositeDisposable();
40 |
41 | this.oRefTextEditorView = atom.views.getView( this.oRefTextEditor );
42 | this.markers = new Markers( this.oRefTextEditor, this.oRefTextEditorView );
43 |
44 | this.oRefTextEditorView.classList.add( "easy-motion-redux-editor" );
45 | this.scrollToCorrectPosition();
46 |
47 | this.handleEvents();
48 | }
49 |
50 | updatePlaceholder() {
51 | let sPlaceholderText;
52 |
53 | switch ( this.sMode ) {
54 | case InputView.MODE_LETTER:
55 | sPlaceholderText = "EasyMotion:Letter";
56 | break;
57 | case InputView.MODE_WORDS_STARTING:
58 | sPlaceholderText = "EasyMotion:Words starting with letter";
59 | break;
60 | case InputView.MODE_WORDS:
61 | sPlaceholderText = "EasyMotion:Words";
62 | break;
63 | case InputView.MODE_LINES:
64 | default:
65 | sPlaceholderText = "EasyMotion:Lines";
66 | break;
67 | }
68 | this.editorInput.element.getModel().setPlaceholderText( sPlaceholderText );
69 | }
70 |
71 | handleEvents() {
72 | this.editorInput.element.addEventListener( "keypress", this.autosubmit.bind( this ) );
73 | this.editorInput.element.addEventListener( "blur", this.remove.bind( this ) );
74 | this.subscriptions.add( atom.commands.add( this.editorInput.element, {
75 | "core:backspace": this.backspace.bind( this ),
76 | "core:confirm": () => {
77 | this.confirm();
78 | },
79 | "core:cancel": () => {
80 | this.goBack();
81 | },
82 | "core:page-up": () => {
83 | this.oRefTextEditor.trigger( "core:page-up" );
84 | },
85 | "core:page-down": () => {
86 | this.oRefTextEditor.trigger( "core:page-down" );
87 | }
88 | } ) );
89 |
90 | const goBack = this.goBack.bind( this );
91 |
92 | this.subscriptions.add(
93 | this.oRefTextEditor.element.onDidChangeScrollTop( goBack ) );
94 | }
95 |
96 | resetPositions() {
97 | this.markers.clear();
98 | if ( !this.inMode( InputView.MODE_LETTER, InputView.MODE_WORDS_STARTING ) ) {
99 | this.loadPositions();
100 | this.groupPositions();
101 | }
102 | }
103 |
104 | hasPositions() {
105 | switch ( this.sMode ) {
106 | case InputView.MODE_LETTER:
107 | case InputView.MODE_WORDS_STARTING:
108 | return this.sLetter ? this.aPositions.length > 0 : true;
109 | case InputView.MODE_WORDS:
110 | case InputView.MODE_LINES:
111 | default:
112 | return this.aPositions.length > 0;
113 | }
114 | }
115 |
116 | autosubmit( oEvent ) {
117 | let sChar = String.fromCharCode( oEvent.charCode );
118 |
119 | if ( !this.sLetter && this.inMode( InputView.MODE_LETTER, InputView.MODE_WORDS_STARTING ) ) {
120 | this.sLetter = sChar;
121 | this.loadPositions();
122 | this.groupPositions();
123 | return false;
124 | }
125 |
126 | this.filterPositions( sChar );
127 | return false;
128 | }
129 |
130 | backspace() {
131 | if ( this.editorInput.getText().length === 0 ) {
132 | this.goBack();
133 | return;
134 | }
135 |
136 | if ( this.inMode( InputView.MODE_LETTER, InputView.MODE_WORDS_STARTING ) ) {
137 | if ( this.editorInput.getText().length === 1 ) {
138 | this.sLetter = null;
139 | this.loadPositions();
140 | this.groupPositions();
141 | } else {
142 | this.loadPositions();
143 | this.groupPositions();
144 | return;
145 | }
146 | }
147 |
148 | this.resetPositions();
149 | }
150 |
151 | remove() {
152 | this.subscriptions.dispose();
153 | this.markers.clear();
154 | this.oRefTextEditorView.classList.remove( "easy-motion-redux-editor" );
155 | super.remove();
156 | }
157 |
158 | confirm() {
159 | let point = this.aPositions[ 0 ][ 0 ];
160 |
161 | if ( this.bSelect ) {
162 | point.column += 1; // include target letter in selection
163 | this.oRefTextEditor.selectToBufferPosition( point );
164 | } else {
165 | this.oRefTextEditor.setCursorBufferPosition( point );
166 | }
167 | this.goBack();
168 | }
169 |
170 | goBack() {
171 | this.oRefTextEditorView.focus();
172 | this.remove();
173 | this.panel.destroy();
174 | }
175 |
176 | focus() {
177 | this.editorInput.focus();
178 | }
179 |
180 | filterPositions( sChar ) {
181 | this.pickPositions( sChar );
182 | const { length } = this.aPositions;
183 |
184 | if ( length === 0 ) {
185 | this.goBack();
186 | } else if ( length > 1 ) {
187 | this.groupPositions();
188 | } else {
189 | this.confirm();
190 | }
191 | }
192 |
193 | groupPositions() {
194 | let iCount = this.aPositions.length,
195 | sReplaceCharacters = atom.config.get( "easy-motion-redux.replaceCharacters" ),
196 | iLast = 0;
197 |
198 | this.oGroupedPositions = {};
199 |
200 | for ( let i of _.range( 0, sReplaceCharacters.length ) ) {
201 | let iTake = Math.floor( iCount / sReplaceCharacters.length );
202 |
203 | if ( i < iCount % sReplaceCharacters.length ) {
204 | iTake += 1;
205 | }
206 |
207 | this.oGroupedPositions[ sReplaceCharacters[ i ] ] = [];
208 | this.aPositions.slice( iLast, iLast + iTake ).forEach( ( oWordStart, j ) => {
209 | let sReplacement,
210 | bSingle = iTake === 1;
211 |
212 | if ( bSingle ) {
213 | sReplacement = sReplaceCharacters[ i ];
214 | } else {
215 | let iCharsAmount = sReplaceCharacters.length,
216 | iRemains = iTake % iCharsAmount,
217 | k;
218 |
219 | if ( iTake <= iCharsAmount ) {
220 | k = j % iTake;
221 | } else if ( iTake < 2 * iCharsAmount && j >= iRemains * 2 ) {
222 | k = j - iRemains;
223 | } else {
224 | k = -1;
225 | }
226 |
227 | sReplacement = sReplaceCharacters[ i ] + ( sReplaceCharacters[ k ] || "•" );
228 | }
229 |
230 | this.oGroupedPositions[ sReplaceCharacters[ i ] ].push( oWordStart );
231 | this.markers.add( oWordStart, sReplacement, {
232 | "single": bSingle
233 | } );
234 | } );
235 |
236 | iLast += iTake;
237 | }
238 | }
239 |
240 | pickPositions( sChar ) {
241 | let sCharacter = sChar;
242 |
243 | this.markers.clear();
244 | if ( sCharacter in this.oGroupedPositions && this.oGroupedPositions[ sCharacter ].length ) {
245 | this.aPositions = this.oGroupedPositions[ sCharacter ];
246 | return;
247 | }
248 |
249 | if ( sCharacter !== sCharacter.toLowerCase() ) {
250 | sCharacter = sCharacter.toLowerCase();
251 | } else if ( sCharacter !== sCharacter.toUpperCase() ) {
252 | sCharacter = sCharacter.toUpperCase();
253 | } else {
254 | return;
255 | }
256 |
257 | if ( sCharacter in this.oGroupedPositions && this.oGroupedPositions[ sCharacter ].length ) {
258 | this.aPositions = this.oGroupedPositions[ sCharacter ];
259 | }
260 | }
261 |
262 | createLetterRegExp( sLetter ) {
263 | const sSearch = ( sLetter || "" ).replace( /([\W]+)/g, "\\$1" );
264 |
265 | return new RegExp( sSearch, "gi" );
266 | }
267 |
268 | loadPositions() {
269 | let oBuffer = this.oRefTextEditor.getBuffer(),
270 | aPositions = [],
271 | fMarkBeginning,
272 | rPositionRegExp;
273 |
274 | fMarkBeginning = ( oObj ) => {
275 | let [ iStart, iEnd ] = [ null, null ];
276 |
277 | iStart = oObj.range.start;
278 | if ( this.sMode === InputView.MODE_WORDS_STARTING ) {
279 | iStart.column = oObj.range.end.column - 1;
280 | }
281 | iEnd = [ iStart.row, iStart.column + 1 ];
282 |
283 | aPositions.push( [ iStart, iEnd ] );
284 | };
285 |
286 | switch ( this.sMode ) {
287 | case InputView.MODE_LETTER:
288 | rPositionRegExp = this.createLetterRegExp( this.sLetter );
289 | break;
290 | case InputView.MODE_WORDS_STARTING:
291 | rPositionRegExp = this.startingLetterWordRegExp( this.sLetter );
292 | break;
293 | case InputView.MODE_WORDS:
294 | rPositionRegExp = this.wordRegExp();
295 | break;
296 | case InputView.MODE_LINES:
297 | default:
298 | break;
299 | }
300 |
301 | if ( this.sMode === InputView.MODE_LINES ) {
302 | aPositions = this.lineBeginngPositions();
303 | } else {
304 | for ( let oRowRange of this.getRowRanges() ) {
305 | oBuffer.scanInRange( rPositionRegExp, oRowRange, fMarkBeginning );
306 | }
307 | }
308 |
309 | this.aPositions = aPositions;
310 | }
311 |
312 | getValidRows() {
313 | const isInputAppearsBeforeThis = this.sMode === InputView.MODE_WORDS_STARTING || this.sMode === InputView.MODE_LETTER,
314 | getLastVisibleScreenRow = this.oRefTextEditorView.getLastVisibleScreenRow(),
315 | iBeginRow = this.oRefTextEditorView.getFirstVisibleScreenRow(),
316 | iEndRow = isInputAppearsBeforeThis ? getLastVisibleScreenRow : getLastVisibleScreenRow - this.getRowPadding(),
317 | aResultingRows = [];
318 |
319 | for ( let iRow of _.range( iBeginRow, iEndRow ) ) {
320 | if ( this.notFolded( iRow ) ) {
321 | aResultingRows.push( iRow );
322 | }
323 | }
324 |
325 | return aResultingRows;
326 | }
327 |
328 | getRowRanges() {
329 | const aRows = this.getValidRows();
330 |
331 | return aRows.map( ( iRow ) => {
332 | return this.getColumnRangeForRow( iRow );
333 | } );
334 | }
335 |
336 | getColumnRangeForRow( iRow ) {
337 | let oBuffer = this.oRefTextEditor.getBuffer(),
338 | iBeginColumn,
339 | iEndColumn,
340 | oRange;
341 |
342 | if ( oBuffer.isRowBlank( iRow ) ) {
343 | return [ [ iRow, 0 ], [ iRow, 0 ] ];
344 | }
345 |
346 | if ( this.oRefTextEditor.isSoftWrapped() ) {
347 | oRange = oBuffer.rangeForRow( iRow );
348 | iBeginColumn = oRange.start.column;
349 | iEndColumn = oRange.end.column;
350 | } else {
351 | oRange = oBuffer.rangeForRow( iRow );
352 | let iMaxColumn = this.oRefTextEditor.getEditorWidthInChars(),
353 | iCharWidth = this.oRefTextEditor.getDefaultCharWidth(),
354 | iLeft = this.oRefTextEditor.element.getScrollLeft();
355 |
356 | if ( iLeft === 0 ) {
357 | iBeginColumn = 0;
358 | iEndColumn = iMaxColumn;
359 | } else {
360 | iBeginColumn = Math.floor( iLeft / iCharWidth );
361 | iEndColumn = iBeginColumn + iMaxColumn;
362 | }
363 | }
364 |
365 | return [ [ iRow, iBeginColumn ], [ iRow, iEndColumn ] ];
366 | }
367 |
368 | getRowPadding() {
369 | let height = this.outerHeight(),
370 | pixelsPerLine = this.oRefTextEditor.getLineHeightInPixels();
371 |
372 | return Math.floor( height / pixelsPerLine );
373 | }
374 |
375 | notFolded( iRow ) {
376 | return iRow === 0 || !this.oRefTextEditor.isFoldedAtBufferRow( iRow ) || !this.oRefTextEditor.isFoldedAtBufferRow( iRow - 1 );
377 | }
378 |
379 | wordRegExp() {
380 | let sNonWordCharacters = atom.config.get( "editor.nonWordCharacters" );
381 |
382 | return new RegExp( `[^\\s${ _.escapeRegExp( sNonWordCharacters ) }]+`, "gi" );
383 | }
384 |
385 | startingLetterWordRegExp( sStartingLetter ) {
386 | let sNonWordCharacters = atom.config.get( "editor.nonWordCharacters" );
387 |
388 | return new RegExp( `(?:^${ sStartingLetter }|[\\s${ _.escapeRegExp( sNonWordCharacters ) }]+${ sStartingLetter })`, "gi" );
389 | }
390 |
391 | lineBeginngPositions() {
392 | const aRows = this.getValidRows();
393 |
394 | return aRows.map( ( row ) => [ [ row, 0 ], [ row, 0 ] ] );
395 | }
396 |
397 | scrollToCorrectPosition() {
398 | if ( this.sMode === InputView.MODE_LINES ) {
399 | const { row } = this.oRefTextEditor.getCursorBufferPosition();
400 |
401 | this.oRefTextEditor.scrollToScreenPosition( [ row, 0 ] );
402 | }
403 | }
404 |
405 | inMode( ...modes ) {
406 | return modes.includes( this.sMode );
407 | }
408 | }
409 |
410 | InputView.MODE_WORDS = "words";
411 | InputView.MODE_LETTER = "letter";
412 | InputView.MODE_WORDS_STARTING = "words_starting";
413 | InputView.MODE_LINES = "lines";
414 |
415 | export default InputView;
416 |
--------------------------------------------------------------------------------
/lib/views/letter.js:
--------------------------------------------------------------------------------
1 | "use babel";
2 |
3 | import { View } from "atom-space-pen-views";
4 |
5 | export default class LetterCoverView extends View {
6 | static content() {
7 | return this.div( {
8 | "class": "easy-motion-redux-letter"
9 | } );
10 | }
11 |
12 | initialize( oTextEditor, oTextEditorView, oRange, sLetter, oOptions ) {
13 | let iHeight = oTextEditor.getLineHeightInPixels();
14 |
15 | this.text( sLetter );
16 | this.addClass( oOptions.single ? "single" : "many" );
17 |
18 | this.css( {
19 | "position": "absolute",
20 | "height": `${ iHeight }px`,
21 | "top": `${ iHeight * -1 }px`,
22 | "left": `${ oTextEditor.getDefaultCharWidth() * -1 }px`
23 | } );
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/lib/views/markers.js:
--------------------------------------------------------------------------------
1 | "use babel";
2 |
3 | import Letter from "./letter";
4 |
5 | export default class Markers {
6 |
7 | constructor( oRefTextEditor, oRefTextEditorView ) {
8 | this.oRefTextEditor = oRefTextEditor;
9 | this.oRefTextEditorView = oRefTextEditorView;
10 | this.aMarkers = [];
11 | }
12 |
13 | add( oRange, sLetter, oOptions ) {
14 | oMarker = this.oRefTextEditor.markBufferRange( oRange );
15 | oDecoration = this.oRefTextEditor.decorateMarker( oMarker, {
16 | "type": "overlay",
17 | "item": new Letter( this.oRefTextEditor, this.oRefTextEditorView, oRange, sLetter, oOptions )
18 | } );
19 | this.aMarkers.push( oMarker );
20 | }
21 |
22 | clear() {
23 | for ( let oMarker of this.aMarkers ) {
24 | oMarker.destroy();
25 | }
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "easy-motion-redux",
3 | "version": "1.3.3",
4 | "main": "./lib/main",
5 | "description": "MovementSpeed++. Jump to any word in your current view super fast. (redux)",
6 | "repository": "https://github.com/leny/atom-easy-motion-redux",
7 | "license": "MIT",
8 | "engines": {
9 | "atom": ">=1.2"
10 | },
11 | "dependencies": {
12 | "atom-space-pen-views": "^2.0.5",
13 | "underscore-plus": "^1.6.6"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/styles/easy-motion-redux.less:
--------------------------------------------------------------------------------
1 | // The ui-variables file is provided by base themes provided by Atom.
2 | //
3 | // See https://github.com/atom/atom-dark-ui/blob/master/stylesheets/ui-variables.less
4 | // for a full listing of what's available.
5 | @import "ui-variables";
6 |
7 | atom-overlay .easy-motion-redux-letter {
8 | position: absolute;
9 | // z-index: 1;
10 | background-color: lighten( @app-background-color, 25% ) !important;
11 | border-radius: 3px;
12 | color: hsl( hue( @text-color-warning ), 100% - saturation( @app-background-color ), 60% - lightness( @app-background-color ) * 0.2 );
13 | }
14 |
--------------------------------------------------------------------------------
/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 | atom-space-pen-views@^2.0.5:
6 | version "2.2.0"
7 | resolved "https://registry.yarnpkg.com/atom-space-pen-views/-/atom-space-pen-views-2.2.0.tgz#a65b2c920ed02f724014fa7d3e5c3d78fbf59997"
8 | dependencies:
9 | fuzzaldrin "^2.1.0"
10 | space-pen "^5.1.2"
11 |
12 | d@1:
13 | version "1.0.0"
14 | resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f"
15 | dependencies:
16 | es5-ext "^0.10.9"
17 |
18 | d@~0.1.1:
19 | version "0.1.1"
20 | resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309"
21 | dependencies:
22 | es5-ext "~0.10.2"
23 |
24 | emissary@^1.2.0:
25 | version "1.3.3"
26 | resolved "https://registry.yarnpkg.com/emissary/-/emissary-1.3.3.tgz#a618d92d682b232d31111dc3625a5df661799606"
27 | dependencies:
28 | es6-weak-map "^0.1.2"
29 | mixto "1.x"
30 | property-accessors "^1.1"
31 | underscore-plus "1.x"
32 |
33 | es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.14, es5-ext@~0.10.2, es5-ext@~0.10.5, es5-ext@~0.10.6:
34 | version "0.10.45"
35 | resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.45.tgz#0bfdf7b473da5919d5adf3bd25ceb754fccc3653"
36 | dependencies:
37 | es6-iterator "~2.0.3"
38 | es6-symbol "~3.1.1"
39 | next-tick "1"
40 |
41 | es6-iterator@~0.1.3:
42 | version "0.1.3"
43 | resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-0.1.3.tgz#d6f58b8c4fc413c249b4baa19768f8e4d7c8944e"
44 | dependencies:
45 | d "~0.1.1"
46 | es5-ext "~0.10.5"
47 | es6-symbol "~2.0.1"
48 |
49 | es6-iterator@~2.0.3:
50 | version "2.0.3"
51 | resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.3.tgz#a7de889141a05a94b0854403b2d0a0fbfa98f3b7"
52 | dependencies:
53 | d "1"
54 | es5-ext "^0.10.35"
55 | es6-symbol "^3.1.1"
56 |
57 | es6-symbol@^3.1.1, es6-symbol@~3.1.1:
58 | version "3.1.1"
59 | resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77"
60 | dependencies:
61 | d "1"
62 | es5-ext "~0.10.14"
63 |
64 | es6-symbol@~2.0.1:
65 | version "2.0.1"
66 | resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-2.0.1.tgz#761b5c67cfd4f1d18afb234f691d678682cb3bf3"
67 | dependencies:
68 | d "~0.1.1"
69 | es5-ext "~0.10.5"
70 |
71 | es6-weak-map@^0.1.2:
72 | version "0.1.4"
73 | resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-0.1.4.tgz#706cef9e99aa236ba7766c239c8b9e286ea7d228"
74 | dependencies:
75 | d "~0.1.1"
76 | es5-ext "~0.10.6"
77 | es6-iterator "~0.1.3"
78 | es6-symbol "~2.0.1"
79 |
80 | fuzzaldrin@^2.1.0:
81 | version "2.1.0"
82 | resolved "https://registry.yarnpkg.com/fuzzaldrin/-/fuzzaldrin-2.1.0.tgz#90204c3e2fdaa6941bb28d16645d418063a90e9b"
83 |
84 | grim@^1.0.0:
85 | version "1.5.0"
86 | resolved "https://registry.yarnpkg.com/grim/-/grim-1.5.0.tgz#b32b08ef567cf1852f81759ed9c68b0d71396a32"
87 | dependencies:
88 | emissary "^1.2.0"
89 |
90 | jquery@2.1.4:
91 | version "2.1.4"
92 | resolved "https://registry.yarnpkg.com/jquery/-/jquery-2.1.4.tgz#228bde698a0c61431dc2630a6a154f15890d2317"
93 |
94 | mixto@1.x:
95 | version "1.0.0"
96 | resolved "https://registry.yarnpkg.com/mixto/-/mixto-1.0.0.tgz#c320ef61b52f2898f522e17d8bbc6d506d8425b6"
97 |
98 | next-tick@1:
99 | version "1.0.0"
100 | resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
101 |
102 | property-accessors@^1.1:
103 | version "1.1.3"
104 | resolved "https://registry.yarnpkg.com/property-accessors/-/property-accessors-1.1.3.tgz#1dde84024631865909ef30703365680c5f928b15"
105 | dependencies:
106 | es6-weak-map "^0.1.2"
107 | mixto "1.x"
108 |
109 | space-pen@^5.1.2:
110 | version "5.1.2"
111 | resolved "https://registry.yarnpkg.com/space-pen/-/space-pen-5.1.2.tgz#22fbbe10e0b044e7b7a47b023da99d94b584ef8f"
112 | dependencies:
113 | grim "^1.0.0"
114 | jquery "2.1.4"
115 | underscore-plus "1.x"
116 |
117 | underscore-plus@1.x, underscore-plus@^1.6.6:
118 | version "1.6.8"
119 | resolved "https://registry.yarnpkg.com/underscore-plus/-/underscore-plus-1.6.8.tgz#894b5132763e9e5ce9d50f2687b68dba6082de22"
120 | dependencies:
121 | underscore "~1.8.3"
122 |
123 | underscore@~1.8.3:
124 | version "1.8.3"
125 | resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
126 |
--------------------------------------------------------------------------------