|
1 | 1 | import * as vscode from 'vscode' |
2 | 2 | import { getActiveRegularEditor } from '@zardoy/vscode-utils' |
3 | | -import { watchExtensionSettings } from '@zardoy/vscode-utils/build/settings' |
4 | | -import { getExtensionSetting, Settings } from 'vscode-framework' |
| 3 | +import { conditionallyRegister } from '@zardoy/vscode-utils/build/settings' |
| 4 | +import { expandPosition } from '@zardoy/vscode-utils/build/position' |
| 5 | +import { getExtensionSetting } from 'vscode-framework' |
5 | 6 | import { oneOf } from '@zardoy/utils' |
6 | 7 |
|
7 | 8 | export default (tsApi: { onCompletionAccepted }) => { |
@@ -61,38 +62,24 @@ export default (tsApi: { onCompletionAccepted }) => { |
61 | 62 | return |
62 | 63 | } |
63 | 64 |
|
64 | | - if (char === ';') { |
65 | | - void vscode.window.activeTextEditor.edit(builder => { |
66 | | - for (const { range } of contentChanges) { |
67 | | - const pos = range.start |
68 | | - builder.delete(new vscode.Range(pos.translate(0, -1), pos)) |
69 | | - } |
70 | | - }) |
| 65 | + if (char === ';' || char === '\n') { |
| 66 | + void vscode.window.activeTextEditor.edit( |
| 67 | + builder => { |
| 68 | + for (const { range } of contentChanges) { |
| 69 | + const pos = range.start |
| 70 | + builder.delete(expandPosition(document, pos, -1)) |
| 71 | + } |
| 72 | + }, |
| 73 | + { |
| 74 | + undoStopAfter: false, |
| 75 | + undoStopBefore: false, |
| 76 | + }, |
| 77 | + ) |
71 | 78 | } |
72 | 79 | } finally { |
73 | 80 | justAcceptedReturnKeywordSuggestion = false |
74 | 81 | } |
75 | 82 | }), |
76 | | - val => val !== 'none', |
| 83 | + () => getExtensionSetting('suggestions.keywordsInsertText') !== 'none', |
77 | 84 | ) |
78 | 85 | } |
79 | | - |
80 | | -const conditionallyRegister = <T extends keyof Settings>( |
81 | | - settingKey: T, |
82 | | - registerFn: () => vscode.Disposable, |
83 | | - acceptSettingValue: (val: Settings[T]) => boolean = val => !!val, |
84 | | -) => { |
85 | | - let disposable: vscode.Disposable | undefined |
86 | | - const changeRegisterState = () => { |
87 | | - const registerState = acceptSettingValue(getExtensionSetting(settingKey)) |
88 | | - if (registerState) { |
89 | | - if (!disposable) disposable = registerFn() |
90 | | - } else { |
91 | | - disposable?.dispose() |
92 | | - disposable = undefined |
93 | | - } |
94 | | - } |
95 | | - |
96 | | - changeRegisterState() |
97 | | - watchExtensionSettings([settingKey], changeRegisterState) |
98 | | -} |
0 commit comments