Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 27d5570

Browse files
authored
Merge pull request #853 from yacut/restore-cursor-position-after-fix
restore cursor position after fix command
2 parents e37cca9 + 1229c28 commit 27d5570

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ module.exports = {
7070
rules = ignoredRulesWhenFixing;
7171
}
7272

73+
const cursorPosition = editor.getCursorBufferPosition();
7374
this.worker.request('job', {
7475
type: 'fix',
7576
config: atom.config.get('linter-eslint'),
7677
rules,
7778
filePath,
7879
projectPath
80+
}).then(() => {
81+
editor.setCursorBufferPosition(cursorPosition);
7982
}).catch(err => {
8083
atom.notifications.addWarning(err.message);
8184
});
@@ -114,13 +117,16 @@ module.exports = {
114117
rules = ignoredRulesWhenFixing;
115118
}
116119

120+
const cursorPosition = textEditor.getCursorBufferPosition();
117121
this.worker.request('job', {
118122
type: 'fix',
119123
config: atom.config.get('linter-eslint'),
120124
rules,
121125
filePath,
122126
projectPath
123-
}).then(response => atom.notifications.addSuccess(response)).catch(err => {
127+
}).then(response => atom.notifications.addSuccess(response)).then(() => {
128+
textEditor.setCursorBufferPosition(cursorPosition);
129+
}).catch(err => {
124130
atom.notifications.addWarning(err.message);
125131
});
126132
}

src/main.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,18 @@ module.exports = {
6666
rules = ignoredRulesWhenFixing
6767
}
6868

69+
// The fix replaces the file content and the cursor jumps automatically
70+
// to the beginning of the file, so save current cursor position
71+
const cursorPosition = editor.getCursorBufferPosition()
6972
this.worker.request('job', {
7073
type: 'fix',
7174
config: atom.config.get('linter-eslint'),
7275
rules,
7376
filePath,
7477
projectPath
78+
}).then(() => {
79+
// set cursor to the position before fix job
80+
editor.setCursorBufferPosition(cursorPosition)
7581
}).catch((err) => {
7682
atom.notifications.addWarning(err.message)
7783
})
@@ -104,6 +110,9 @@ module.exports = {
104110
rules = ignoredRulesWhenFixing
105111
}
106112

113+
// The fix replaces the file content and the cursor jumps automatically
114+
// to the beginning of the file, so save current cursor position
115+
const cursorPosition = textEditor.getCursorBufferPosition()
107116
this.worker.request('job', {
108117
type: 'fix',
109118
config: atom.config.get('linter-eslint'),
@@ -112,7 +121,10 @@ module.exports = {
112121
projectPath
113122
}).then(response =>
114123
atom.notifications.addSuccess(response)
115-
).catch((err) => {
124+
).then(() => {
125+
// set cursor to the position before fix job
126+
textEditor.setCursorBufferPosition(cursorPosition)
127+
}).catch((err) => {
116128
atom.notifications.addWarning(err.message)
117129
})
118130
}

0 commit comments

Comments
 (0)