Revert "fix #43270"

This reverts commit 556bfbeee6.
This commit is contained in:
Johannes Rieken 2019-04-29 12:46:18 +02:00
parent 013007a8c1
commit 43061a50fd
4 changed files with 15 additions and 54 deletions

View file

@ -19,7 +19,6 @@ import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from '
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ILogService } from 'vs/platform/log/common/log';
import { SnippetSession } from './snippetSession';
import { EditorState, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState';
export class SnippetController2 implements IEditorContribution {
@ -114,26 +113,10 @@ export class SnippetController2 implements IEditorContribution {
this._updateState();
// we listen on model and selection changes. usually
// both events come in together and this is to prevent
// that we don't call _updateState twice.
let state: EditorState;
let dedupedUpdateState = () => {
if (!state || !state.validate(this._editor)) {
this._updateState();
state = new EditorState(this._editor, CodeEditorStateFlag.Selection | CodeEditorStateFlag.Value);
}
};
this._snippetListener = [
this._editor.onDidChangeModelContent(e => {
if (e.isFlush) {
this.cancel();
} else {
setTimeout(dedupedUpdateState, 0);
}
}),
this._editor.onDidChangeCursorSelection(dedupedUpdateState),
this._editor.onDidChangeModelContent(e => e.isFlush && this.cancel()),
this._editor.onDidChangeModel(() => this.cancel()),
this._editor.onDidChangeCursorSelection(() => this._updateState())
];
}

View file

@ -198,6 +198,10 @@ export class OneSnippet {
let ranges: Range[] | undefined;
for (const placeholder of placeholdersWithEqualIndex) {
if (placeholder.isFinalTabstop) {
// ignore those
break;
}
if (!ranges) {
ranges = [];
@ -571,12 +575,6 @@ export class SnippetSession {
return false;
}
if (allPossibleSelections.has(0)) {
// selection overlaps with a final tab stop which means
// we done
return false;
}
// add selections from 'this' snippet so that we know all
// selections for this placeholder
allPossibleSelections.forEach((array, index) => {

View file

@ -11,7 +11,6 @@ import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKe
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { NullLogService } from 'vs/platform/log/common/log';
import { Handler } from 'vs/editor/common/editorCommon';
import { timeout } from 'vs/base/common/async';
suite('SnippetController2', function () {
@ -134,11 +133,11 @@ suite('SnippetController2', function () {
assertSelections(editor, new Selection(1, 1, 1, 7), new Selection(2, 5, 2, 11));
editor.trigger('test', 'cut', {});
assertContextKeys(contextKeys, false, false, false);
assertContextKeys(contextKeys, true, false, true);
assertSelections(editor, new Selection(1, 1, 1, 1), new Selection(2, 5, 2, 5));
editor.trigger('test', 'type', { text: 'abc' });
assertContextKeys(contextKeys, false, false, false);
assertContextKeys(contextKeys, true, false, true);
ctrl.next();
assertContextKeys(contextKeys, false, false, false);
@ -160,9 +159,9 @@ suite('SnippetController2', function () {
assertSelections(editor, new Selection(1, 4, 1, 4), new Selection(2, 8, 2, 8));
assertContextKeys(contextKeys, true, false, true);
// ctrl.next();
// assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
// assertContextKeys(contextKeys, true, true, true);
ctrl.next();
assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
assertContextKeys(contextKeys, true, true, true);
ctrl.next();
assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
@ -177,10 +176,10 @@ suite('SnippetController2', function () {
ctrl.insert('farboo');
assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
// assertContextKeys(contextKeys, true, false, true);
assertContextKeys(contextKeys, true, false, true);
// ctrl.next();
// assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
ctrl.next();
assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
assertContextKeys(contextKeys, false, false, false);
});
@ -402,23 +401,4 @@ suite('SnippetController2', function () {
assertContextKeys(contextKeys, false, false, false);
assertSelections(editor, new Selection(1, 22, 1, 22));
});
test('A little confusing visual effect of highlighting for snippet tabstop #43270', async function () {
const ctrl = new SnippetController2(editor, logService, contextKeys);
model.setValue('');
editor.setSelection(new Selection(1, 1, 1, 1));
ctrl.insert('background-color: ${1:fff};$0');
assertSelections(editor, new Selection(1, 19, 1, 22));
editor.setSelection(new Selection(1, 22, 1, 22));
assertContextKeys(contextKeys, true, false, true);
editor.trigger('', 'deleteRight', null);
assert.equal(model.getValue(), 'background-color: fff');
await timeout(0); // this depends on re-scheduling of events...
assertContextKeys(contextKeys, false, false, false);
});
});

View file

@ -331,7 +331,7 @@ suite('SnippetSession', function () {
// reset selection to placeholder
session.next();
assert.equal(session.isSelectionWithinPlaceholders(), false);
assert.equal(session.isSelectionWithinPlaceholders(), true);
assert.equal(session.isAtLastPlaceholder, true);
assertSelections(editor, new Selection(1, 13, 1, 13), new Selection(2, 17, 2, 17));
});