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

Commit

Permalink
Merge pull request #853 from yacut/restore-cursor-position-after-fix
Browse files Browse the repository at this point in the history
restore cursor position after fix command
  • Loading branch information
IanVS authored Mar 20, 2017
2 parents e37cca9 + 1229c28 commit 27d5570
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
}
Expand Down
14 changes: 13 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ 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',
config: atom.config.get('linter-eslint'),
rules,
filePath,
projectPath
}).then(() => {
// set cursor to the position before fix job
editor.setCursorBufferPosition(cursorPosition)
}).catch((err) => {
atom.notifications.addWarning(err.message)
})
Expand Down Expand Up @@ -104,6 +110,9 @@ 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',
config: atom.config.get('linter-eslint'),
Expand All @@ -112,7 +121,10 @@ module.exports = {
projectPath
}).then(response =>
atom.notifications.addSuccess(response)
).catch((err) => {
).then(() => {
// set cursor to the position before fix job
textEditor.setCursorBufferPosition(cursorPosition)
}).catch((err) => {
atom.notifications.addWarning(err.message)
})
}
Expand Down

0 comments on commit 27d5570

Please sign in to comment.