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

restore cursor position after fix command #853

Merged
merged 2 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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