Skip to content
Open
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
10 changes: 5 additions & 5 deletions packages/spell-check/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"endOfLine": "lf",
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5"
"endOfLine": "lf",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}
45 changes: 22 additions & 23 deletions packages/spell-check/lib/checker-env.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
module.exports = {
isLinux() {
return /linux/.test(process.platform);
},
isWindows() {
return /win32/.test(process.platform);
}, // TODO: Windows < 8 or >= 8
isDarwin() {
return /darwin/.test(process.platform);
},
preferHunspell() {
return !!process.env.SPELLCHECKER_PREFER_HUNSPELL;
},

isSystemSupported() {
return this.isWindows() || this.isDarwin();
},
isLocaleSupported() {
return true;
},

useLocales() {
return this.isLinux() || this.isWindows() || this.preferHunspell();
},
isLinux() {
return /linux/.test(process.platform);
},
isWindows() {
// TODO: Windows < 8 or >= 8
return /win32/.test(process.platform);
},
isDarwin() {
return /darwin/.test(process.platform);
},
preferHunspell() {
return !!process.env.SPELLCHECKER_PREFER_HUNSPELL;
},
isSystemSupported() {
return this.isWindows() || this.isDarwin();
},
isLocaleSupported() {
return true;
},
useLocales() {
return this.isLinux() || this.isWindows() || this.preferHunspell();
},
};
185 changes: 89 additions & 96 deletions packages/spell-check/lib/corrections-view.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,95 @@
/** @babel */
const SelectListView = require('atom-select-list');

import SelectListView from 'atom-select-list';
module.exports = class CorrectionsView {
constructor(editor, corrections, marker, updateTarget, updateCallback) {
this.editor = editor;
this.corrections = corrections;
this.marker = marker;
this.updateTarget = updateTarget;
this.updateCallback = updateCallback;

export default class CorrectionsView {
constructor(editor, corrections, marker, updateTarget, updateCallback) {
this.editor = editor;
this.corrections = corrections;
this.marker = marker;
this.updateTarget = updateTarget;
this.updateCallback = updateCallback;
this.selectListView = new SelectListView({
emptyMessage: 'No corrections',
items: this.corrections,
filterKeyForItem: (item) => item.label,
elementForItem: (item) => {
const element = document.createElement('li');
if (item.isSuggestion) {
// This is a word replacement suggestion.
element.textContent = item.label;
} else {
// This is an operation such as add word.
const em = document.createElement('em');
em.textContent = item.label;
element.appendChild(em);
}
return element;
},
didConfirmSelection: (item) => {
this.editor.transact(() => {
if (item.isSuggestion) {
// Update the buffer with the correction.
this.editor.setSelectedBufferRange(
this.marker.getBufferRange()
);
this.editor.insertText(item.suggestion);
} else {
// Build up the arguments object for this buffer and text.
let projectPath = null;
let relativePath = null;
if (
this.editor &&
this.editor.buffer &&
this.editor.buffer.file &&
this.editor.buffer.file.path
) {
[
projectPath,
relativePath,
] = atom.project.relativizePath(
this.editor.buffer.file.path
);
}
this.selectListView = new SelectListView({
emptyMessage: 'No corrections',
items: this.corrections,
filterKeyForItem: (item) => item.label,
elementForItem: (item) => {
const element = document.createElement('li');
if (item.isSuggestion) {
// This is a word replacement suggestion.
element.textContent = item.label;
} else {
// This is an operation such as add word.
const em = document.createElement('em');
em.textContent = item.label;
element.appendChild(em);
}
return element;
},
didConfirmSelection: (item) => {
this.editor.transact(() => {
if (item.isSuggestion) {
// Update the buffer with the correction.
this.editor.setSelectedBufferRange(this.marker.getBufferRange());
this.editor.insertText(item.suggestion);
} else {
// Build up the arguments object for this buffer and text.
let projectPath = null;
let relativePath = null;
if (
this.editor &&
this.editor.buffer &&
this.editor.buffer.file &&
this.editor.buffer.file.path
) {
[projectPath, relativePath] = atom.project.relativizePath(
this.editor.buffer.file.path
);
}

const args = { id: this.id, projectPath, relativePath };
// Send the "add" request to the plugin.
item.plugin.add(args, item);
// Update the buffer to handle the corrections.
this.updateCallback.bind(this.updateTarget)();
}
});
this.destroy();
},
didConfirmEmptySelection: () => {
this.destroy();
},
didCancelSelection: () => {
this.destroy();
},
const args = { id: this.id, projectPath, relativePath };
// Send the "add" request to the plugin.
item.plugin.add(args, item);
// Update the buffer to handle the corrections.
this.updateCallback.bind(this.updateTarget)();
}
});
this.selectListView.element.classList.add(
'spell-check-corrections',
'corrections',
'popover-list'
);
}
this.destroy();
},
didConfirmEmptySelection: () => {
this.destroy();
},
didCancelSelection: () => {
this.destroy();
},
});

attach() {
this.previouslyFocusedElement = document.activeElement;
this.overlayDecoration = this.editor.decorateMarker(this.marker, {
type: 'overlay',
item: this.selectListView,
});
process.nextTick(() => {
atom.views.readDocument(() => {
this.selectListView.focus();
});
});
}
this.selectListView.element.classList.add(
'spell-check-corrections',
'corrections',
'popover-list'
);
}

async destroy() {
if (!this.destroyed) {
this.destroyed = true;
this.overlayDecoration.destroy();
await this.selectListView.destroy();
if (this.previouslyFocusedElement) {
this.previouslyFocusedElement.focus();
this.previouslyFocusedElement = null;
}
}
}
}
attach() {
this.previouslyFocusedElement = document.activeElement;
this.overlayDecoration = this.editor.decorateMarker(this.marker, {
type: 'overlay',
item: this.selectListView,
});

process.nextTick(() => {
atom.views.readDocument(() => this.selectListView.focus());
});
}

async destroy() {
if (this.destroyed) return;
this.destroyed = true;

this.overlayDecoration.destroy();
await this.selectListView.destroy();

this.previouslyFocusedElement?.focus();
this.previouslyFocusedElement &&= null;
}
};
Loading
Loading