From a3441a51d563a8d6d7b220f464abd8135562e1a9 Mon Sep 17 00:00:00 2001 From: yacut Date: Fri, 17 Mar 2017 08:20:02 +0100 Subject: [PATCH 1/2] restore cursor position after fix command --- lib/main.js | 8 +++++++- src/main.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index afc4c493..4513d874 100644 --- a/lib/main.js +++ b/lib/main.js @@ -70,12 +70,15 @@ module.exports = { rules = ignoredRulesWhenFixing; } + const cursorPosition = editor.getCursorBufferPosition(); this.worker.request('job', { type: 'fix', config: atom.config.get('linter-eslint'), rules, filePath, projectPath + }).then(() => { + editor.setCursorBufferPosition(cursorPosition); }).catch(err => { atom.notifications.addWarning(err.message); }); @@ -114,13 +117,16 @@ module.exports = { rules = ignoredRulesWhenFixing; } + const cursorPosition = textEditor.getCursorBufferPosition(); this.worker.request('job', { type: 'fix', config: atom.config.get('linter-eslint'), rules, filePath, projectPath - }).then(response => atom.notifications.addSuccess(response)).catch(err => { + }).then(response => atom.notifications.addSuccess(response)).then(() => { + textEditor.setCursorBufferPosition(cursorPosition); + }).catch(err => { atom.notifications.addWarning(err.message); }); } diff --git a/src/main.js b/src/main.js index 9d419e85..2dfb3139 100644 --- a/src/main.js +++ b/src/main.js @@ -66,12 +66,15 @@ module.exports = { rules = ignoredRulesWhenFixing } + const cursorPosition = editor.getCursorBufferPosition() this.worker.request('job', { type: 'fix', config: atom.config.get('linter-eslint'), rules, filePath, projectPath + }).then(() => { + editor.setCursorBufferPosition(cursorPosition) }).catch((err) => { atom.notifications.addWarning(err.message) }) @@ -104,6 +107,7 @@ module.exports = { rules = ignoredRulesWhenFixing } + const cursorPosition = textEditor.getCursorBufferPosition() this.worker.request('job', { type: 'fix', config: atom.config.get('linter-eslint'), @@ -112,7 +116,9 @@ module.exports = { projectPath }).then(response => atom.notifications.addSuccess(response) - ).catch((err) => { + ).then(() => { + textEditor.setCursorBufferPosition(cursorPosition) + }).catch((err) => { atom.notifications.addWarning(err.message) }) } From 1229c28de01829d12ff31addd927c2025d327f22 Mon Sep 17 00:00:00 2001 From: yacut Date: Mon, 20 Mar 2017 21:36:43 +0100 Subject: [PATCH 2/2] 853 add some comments to explain the issue --- src/main.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.js b/src/main.js index 2dfb3139..3ae9caa5 100644 --- a/src/main.js +++ b/src/main.js @@ -66,6 +66,8 @@ module.exports = { rules = ignoredRulesWhenFixing } + // The fix replaces the file content and the cursor jumps automatically + // to the beginning of the file, so save current cursor position const cursorPosition = editor.getCursorBufferPosition() this.worker.request('job', { type: 'fix', @@ -74,6 +76,7 @@ module.exports = { filePath, projectPath }).then(() => { + // set cursor to the position before fix job editor.setCursorBufferPosition(cursorPosition) }).catch((err) => { atom.notifications.addWarning(err.message) @@ -107,6 +110,8 @@ module.exports = { rules = ignoredRulesWhenFixing } + // The fix replaces the file content and the cursor jumps automatically + // to the beginning of the file, so save current cursor position const cursorPosition = textEditor.getCursorBufferPosition() this.worker.request('job', { type: 'fix', @@ -117,6 +122,7 @@ module.exports = { }).then(response => atom.notifications.addSuccess(response) ).then(() => { + // set cursor to the position before fix job textEditor.setCursorBufferPosition(cursorPosition) }).catch((err) => { atom.notifications.addWarning(err.message)