mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-22 12:50:29 -04:00
Merge from master
This commit is contained in:
@@ -2,31 +2,30 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { ScrollType, IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { FindMatch, TrackedRangeStickiness, OverviewRulerLane, ITextModel } from 'vs/editor/common/model';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction } from 'vs/editor/browser/editorExtensions';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
|
||||
import { RevealTarget } from 'vs/editor/common/controller/cursorCommon';
|
||||
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { CursorMoveCommands } from 'vs/editor/common/controller/cursorMoveCommands';
|
||||
import { RevealTarget } from 'vs/editor/common/controller/cursorCommon';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Constants } from 'vs/editor/common/core/uint';
|
||||
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { FindMatch, ITextModel, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
import { DocumentHighlightProviderRegistry } from 'vs/editor/common/modes';
|
||||
import { CommonFindController } from 'vs/editor/contrib/find/findController';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
import { FindOptionOverride, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
|
||||
import { MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { overviewRulerSelectionHighlightForeground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
|
||||
import { INewFindReplaceState, FindOptionOverride } from 'vs/editor/contrib/find/findState';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { MenuId } from 'vs/platform/actions/common/actions';
|
||||
|
||||
export class InsertCursorAbove extends EditorAction {
|
||||
|
||||
@@ -166,6 +165,57 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction {
|
||||
}
|
||||
}
|
||||
|
||||
class InsertCursorAtEndOfLineSelected extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.addCursorsToBottom',
|
||||
label: nls.localize('mutlicursor.addCursorsToBottom', "Add Cursors To Bottom"),
|
||||
alias: 'Add Cursors To Bottom',
|
||||
precondition: null
|
||||
});
|
||||
}
|
||||
|
||||
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const selections = editor.getSelections();
|
||||
const lineCount = editor.getModel().getLineCount();
|
||||
|
||||
let newSelections = [];
|
||||
for (let i = selections[0].startLineNumber; i <= lineCount; i++) {
|
||||
newSelections.push(new Selection(i, selections[0].startColumn, i, selections[0].endColumn));
|
||||
}
|
||||
|
||||
if (newSelections.length > 0) {
|
||||
editor.setSelections(newSelections);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class InsertCursorAtTopOfLineSelected extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.addCursorsToTop',
|
||||
label: nls.localize('mutlicursor.addCursorsToTop', "Add Cursors To Top"),
|
||||
alias: 'Add Cursors To Top',
|
||||
precondition: null
|
||||
});
|
||||
}
|
||||
|
||||
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const selections = editor.getSelections();
|
||||
|
||||
let newSelections = [];
|
||||
for (let i = selections[0].startLineNumber; i >= 1; i--) {
|
||||
newSelections.push(new Selection(i, selections[0].startColumn, i, selections[0].endColumn));
|
||||
}
|
||||
|
||||
if (newSelections.length > 0) {
|
||||
editor.setSelections(newSelections);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class MultiCursorSessionResult {
|
||||
constructor(
|
||||
public readonly selections: Selection[],
|
||||
@@ -207,7 +257,7 @@ export class MultiCursorSession {
|
||||
const s = editor.getSelection();
|
||||
|
||||
let searchText: string;
|
||||
let currentMatch: Selection = null;
|
||||
let currentMatch: Selection | null = null;
|
||||
|
||||
if (s.isEmpty()) {
|
||||
// selection is empty => expand to current word
|
||||
@@ -477,7 +527,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
|
||||
}
|
||||
|
||||
public selectAll(findController: CommonFindController): void {
|
||||
let matches: FindMatch[] = null;
|
||||
let matches: FindMatch[] | null = null;
|
||||
|
||||
const findState = findController.getState();
|
||||
|
||||
@@ -663,13 +713,11 @@ export class CompatChangeAll extends MultiCursorSelectionControllerAction {
|
||||
}
|
||||
|
||||
class SelectionHighlighterState {
|
||||
public readonly lastWordUnderCursor: Selection;
|
||||
public readonly searchText: string;
|
||||
public readonly matchCase: boolean;
|
||||
public readonly wordSeparators: string;
|
||||
|
||||
constructor(lastWordUnderCursor: Selection, searchText: string, matchCase: boolean, wordSeparators: string) {
|
||||
this.lastWordUnderCursor = lastWordUnderCursor;
|
||||
constructor(searchText: string, matchCase: boolean, wordSeparators: string) {
|
||||
this.searchText = searchText;
|
||||
this.matchCase = matchCase;
|
||||
this.wordSeparators = wordSeparators;
|
||||
@@ -723,7 +771,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
|
||||
|
||||
if (e.selection.isEmpty()) {
|
||||
if (e.reason === CursorChangeReason.Explicit) {
|
||||
if (this.state && (!this.state.lastWordUnderCursor || !this.state.lastWordUnderCursor.containsPosition(e.selection.getStartPosition()))) {
|
||||
if (this.state) {
|
||||
// no longer valid
|
||||
this._setState(null);
|
||||
}
|
||||
@@ -791,21 +839,10 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
|
||||
return null;
|
||||
}
|
||||
|
||||
let lastWordUnderCursor: Selection = null;
|
||||
const hasFindOccurrences = DocumentHighlightProviderRegistry.has(model);
|
||||
if (r.currentMatch) {
|
||||
// This is an empty selection
|
||||
if (hasFindOccurrences) {
|
||||
// Do not interfere with semantic word highlighting in the no selection case
|
||||
return null;
|
||||
}
|
||||
|
||||
const config = editor.getConfiguration();
|
||||
if (!config.contribInfo.occurrencesHighlight) {
|
||||
return null;
|
||||
}
|
||||
|
||||
lastWordUnderCursor = r.currentMatch;
|
||||
// Do not interfere with semantic word highlighting in the no selection case
|
||||
return null;
|
||||
}
|
||||
if (/^[ \t]+$/.test(r.searchText)) {
|
||||
// whitespace only selection
|
||||
@@ -837,7 +874,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
|
||||
}
|
||||
}
|
||||
|
||||
return new SelectionHighlighterState(lastWordUnderCursor, r.searchText, r.matchCase, r.wholeWord ? editor.getConfiguration().wordSeparators : null);
|
||||
return new SelectionHighlighterState(r.searchText, r.matchCase, r.wholeWord ? editor.getConfiguration().wordSeparators : null);
|
||||
}
|
||||
|
||||
private _setState(state: SelectionHighlighterState): void {
|
||||
@@ -910,7 +947,6 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
|
||||
className: 'selectionHighlight',
|
||||
overviewRuler: {
|
||||
color: themeColorFromId(overviewRulerSelectionHighlightForeground),
|
||||
darkColor: themeColorFromId(overviewRulerSelectionHighlightForeground),
|
||||
position: OverviewRulerLane.Center
|
||||
}
|
||||
});
|
||||
@@ -958,3 +994,5 @@ registerEditorAction(MoveSelectionToNextFindMatchAction);
|
||||
registerEditorAction(MoveSelectionToPreviousFindMatchAction);
|
||||
registerEditorAction(SelectHighlightsAction);
|
||||
registerEditorAction(CompatChangeAll);
|
||||
registerEditorAction(InsertCursorAtEndOfLineSelected);
|
||||
registerEditorAction(InsertCursorAtTopOfLineSelected);
|
||||
@@ -2,18 +2,17 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { withTestCodeEditor, TestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { InsertCursorAbove, InsertCursorBelow, MultiCursorSelectionController, SelectHighlightsAction, AddSelectionToNextFindMatchAction } from 'vs/editor/contrib/multicursor/multicursor';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLineSequence } from 'vs/editor/common/model';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { CommonFindController } from 'vs/editor/contrib/find/findController';
|
||||
import { AddSelectionToNextFindMatchAction, InsertCursorAbove, InsertCursorBelow, MultiCursorSelectionController, SelectHighlightsAction } from 'vs/editor/contrib/multicursor/multicursor';
|
||||
import { TestCodeEditor, withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
|
||||
suite('Multicursor', () => {
|
||||
|
||||
@@ -61,9 +60,14 @@ suite('Multicursor selection', () => {
|
||||
let queryState: { [key: string]: any; } = {};
|
||||
let serviceCollection = new ServiceCollection();
|
||||
serviceCollection.set(IStorageService, {
|
||||
_serviceBrand: undefined,
|
||||
onDidChangeStorage: Event.None,
|
||||
onWillSaveState: Event.None,
|
||||
get: (key: string) => queryState[key],
|
||||
getBoolean: (key: string) => !!queryState[key],
|
||||
store: (key: string, value: any) => { queryState[key] = value; }
|
||||
getInteger: (key: string) => undefined,
|
||||
store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); },
|
||||
remove: (key) => void 0
|
||||
} as IStorageService);
|
||||
|
||||
test('issue #8817: Cursor position changes when you cancel multicursor', () => {
|
||||
|
||||
Reference in New Issue
Block a user