Skip to content

Commit 98eddd0

Browse files
committed
Use async/await
1 parent 284d06f commit 98eddd0

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

lib/clipboard.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class Clipboard {
88
this._platform = params.platform;
99
}
1010

11-
read() {
12-
return this._clipboardy.read()
13-
.then(text => this._windows ? this._dropCRFromEOL(text) : text);
11+
async read() {
12+
const text = await this._clipboardy.read();
13+
return this._windows ? this._dropCRFromEOL(text) : text;
1414
}
1515

1616
get _windows() {

lib/commands/compare-selection-with-clipboard.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ class CompareSelectionWithClipboardCommand {
1111
this._logger = params.logger;
1212
}
1313

14-
execute(editor) {
15-
return Promise.resolve()
16-
.then(() => this._clipboard.read())
17-
.then(text => {
18-
this._selectionInfoRegistry.set(TextKey.CLIPBOARD, {text, fileName: 'Clipboard'});
19-
20-
const textInfo = this._selectionInfoBuilder.extract(editor);
21-
this._selectionInfoRegistry.set(TextKey.REGISTER2, textInfo);
22-
return this._diffPresenter.takeDiff(TextKey.CLIPBOARD, TextKey.REGISTER2);
23-
})
24-
.catch(this._handleError.bind(this));
14+
async execute(editor) {
15+
try {
16+
const text = await this._clipboard.read();
17+
this._selectionInfoRegistry.set(TextKey.CLIPBOARD, {text, fileName: 'Clipboard'});
18+
19+
const textInfo = this._selectionInfoBuilder.extract(editor);
20+
this._selectionInfoRegistry.set(TextKey.REGISTER2, textInfo);
21+
22+
await this._diffPresenter.takeDiff(TextKey.CLIPBOARD, TextKey.REGISTER2);
23+
} catch (e) {
24+
this._handleError(e);
25+
}
2526
}
2627

2728
_handleError(e) {

lib/commands/compare-selection-with-text1.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ class CompareSelectionWithText1Command {
1010
this._selectionInfoRegistry = params.selectionInfoRegistry;
1111
}
1212

13-
execute(editor) {
14-
return Promise.resolve().then(() => {
13+
async execute(editor) {
14+
try {
1515
const textInfo = this._selectionInfoBuilder.extract(editor);
1616
this._selectionInfoRegistry.set(TextKey.REGISTER2, textInfo);
17-
return this._diffPresenter.takeDiff(TextKey.REGISTER1, TextKey.REGISTER2);
18-
}).catch(this._handleError.bind(this));
17+
18+
await this._diffPresenter.takeDiff(TextKey.REGISTER1, TextKey.REGISTER2);
19+
} catch (e) {
20+
this._handleError(e);
21+
}
1922
}
2023

2124
_handleError(e) {

0 commit comments

Comments
 (0)