提交 7d098ad4 编写于 作者: A Alex Dima

Merge view cursor position & selection changed events into a single event (#26730)

上级 0e3d227c
......@@ -134,8 +134,8 @@ export class MouseHandler extends ViewEventHandler {
}
// --- begin event handlers
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): boolean {
this._mouseDownOperation.onCursorSelectionChanged(e);
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
this._mouseDownOperation.onCursorStateChanged(e);
return false;
}
private _isFocused = false;
......@@ -411,8 +411,8 @@ class MouseDownOperation extends Disposable {
}, 10);
}
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): void {
this._currentSelection = e.selection;
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): void {
this._currentSelection = e.selections[0];
}
private _getPositionOutsideEditor(e: EditorMouseEvent): MouseTarget {
......
......@@ -292,8 +292,8 @@ export class TextAreaHandler extends ViewPart {
return true;
}
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): boolean {
this._selections = [e.selection].concat(e.secondarySelections);
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
this._selections = e.selections.slice(0);
return true;
}
public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean {
......
......@@ -63,25 +63,28 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
}
return true;
}
public onCursorPositionChanged(e: viewEvents.ViewCursorPositionChangedEvent): boolean {
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
let hasChanged = false;
if (this._primaryCursorIsInEditableRange !== e.isInEditableRange) {
this._primaryCursorIsInEditableRange = e.isInEditableRange;
hasChanged = true;
}
if (this._primaryCursorLineNumber !== e.position.lineNumber) {
this._primaryCursorLineNumber = e.position.lineNumber;
const primaryCursorLineNumber = e.selections[0].positionLineNumber;
if (this._primaryCursorLineNumber !== primaryCursorLineNumber) {
this._primaryCursorLineNumber = primaryCursorLineNumber;
hasChanged = true;
}
return hasChanged;
}
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): boolean {
let isEmpty = e.selection.isEmpty();
if (this._selectionIsEmpty !== isEmpty) {
this._selectionIsEmpty = isEmpty;
const selectionIsEmpty = e.selections[0].isEmpty();
if (this._selectionIsEmpty !== selectionIsEmpty) {
this._selectionIsEmpty = selectionIsEmpty;
hasChanged = true;
return true;
}
return false;
return hasChanged;
}
public onFlushed(e: viewEvents.ViewFlushedEvent): boolean {
return true;
......
......@@ -54,16 +54,20 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay {
}
return true;
}
public onCursorPositionChanged(e: viewEvents.ViewCursorPositionChangedEvent): boolean {
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
let hasChanged = false;
if (this._primaryCursorIsInEditableRange !== e.isInEditableRange) {
this._primaryCursorIsInEditableRange = e.isInEditableRange;
hasChanged = true;
}
if (this._primaryCursorLineNumber !== e.position.lineNumber) {
this._primaryCursorLineNumber = e.position.lineNumber;
const primaryCursorLineNumber = e.selections[0].positionLineNumber;
if (this._primaryCursorLineNumber !== primaryCursorLineNumber) {
this._primaryCursorLineNumber = primaryCursorLineNumber;
hasChanged = true;
}
return hasChanged;
}
public onFlushed(e: viewEvents.ViewFlushedEvent): boolean {
......
......@@ -65,8 +65,9 @@ export class LineNumbersOverlay extends DynamicViewOverlay {
this._readConfig();
return true;
}
public onCursorPositionChanged(e: viewEvents.ViewCursorPositionChangedEvent): boolean {
this._lastCursorModelPosition = this._context.model.coordinatesConverter.convertViewPositionToModelPosition(e.position);
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
const primaryViewPosition = e.selections[0].getPosition();
this._lastCursorModelPosition = this._context.model.coordinatesConverter.convertViewPositionToModelPosition(primaryViewPosition);
if (this._renderRelativeLineNumbers) {
return true;
......
......@@ -122,10 +122,12 @@ export class DecorationsOverviewRuler extends ViewPart {
return true;
}
public onCursorPositionChanged(e: viewEvents.ViewCursorPositionChangedEvent): boolean {
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
this._shouldUpdateCursorPosition = true;
this._cursorPositions = [e.position];
this._cursorPositions = this._cursorPositions.concat(e.secondaryPositions);
this._cursorPositions = [];
for (let i = 0, len = e.selections.length; i < len; i++) {
this._cursorPositions[i] = e.selections[i].getPosition();
}
return true;
}
......
......@@ -110,9 +110,8 @@ export class SelectionsOverlay extends DynamicViewOverlay {
}
return true;
}
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): boolean {
this._selections = [e.selection];
this._selections = this._selections.concat(e.secondarySelections);
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
this._selections = e.selections.slice(0);
return true;
}
public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean {
......
......@@ -99,41 +99,48 @@ export class ViewCursors extends ViewPart {
}
return true;
}
public onCursorPositionChanged(e: viewEvents.ViewCursorPositionChangedEvent): boolean {
this._primaryCursor.onCursorPositionChanged(e.position, e.isInEditableRange);
private _onCursorPositionChanged(position: Position, secondaryPositions: Position[], isInEditableRange: boolean): void {
this._primaryCursor.onCursorPositionChanged(position, isInEditableRange);
this._updateBlinking();
if (this._secondaryCursors.length < e.secondaryPositions.length) {
if (this._secondaryCursors.length < secondaryPositions.length) {
// Create new cursors
let addCnt = e.secondaryPositions.length - this._secondaryCursors.length;
let addCnt = secondaryPositions.length - this._secondaryCursors.length;
for (let i = 0; i < addCnt; i++) {
let newCursor = new ViewCursor(this._context, true);
this._domNode.domNode.insertBefore(newCursor.getDomNode().domNode, this._primaryCursor.getDomNode().domNode.nextSibling);
this._secondaryCursors.push(newCursor);
}
} else if (this._secondaryCursors.length > e.secondaryPositions.length) {
} else if (this._secondaryCursors.length > secondaryPositions.length) {
// Remove some cursors
let removeCnt = this._secondaryCursors.length - e.secondaryPositions.length;
let removeCnt = this._secondaryCursors.length - secondaryPositions.length;
for (let i = 0; i < removeCnt; i++) {
this._domNode.removeChild(this._secondaryCursors[0].getDomNode());
this._secondaryCursors.splice(0, 1);
}
}
for (let i = 0; i < e.secondaryPositions.length; i++) {
this._secondaryCursors[i].onCursorPositionChanged(e.secondaryPositions[i], e.isInEditableRange);
for (let i = 0; i < secondaryPositions.length; i++) {
this._secondaryCursors[i].onCursorPositionChanged(secondaryPositions[i], isInEditableRange);
}
return true;
}
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): boolean {
let selectionIsEmpty = e.selection.isEmpty();
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
let positions: Position[] = [];
for (let i = 0, len = e.selections.length; i < len; i++) {
positions[i] = e.selections[i].getPosition();
}
this._onCursorPositionChanged(positions[0], positions.slice(1), e.isInEditableRange);
const selectionIsEmpty = e.selections[0].isEmpty();
if (this._selectionIsEmpty !== selectionIsEmpty) {
this._selectionIsEmpty = selectionIsEmpty;
this._updateDomClassName();
}
return false;
return true;
}
public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean {
// true for inline decorations that can end up relayouting text
return true;
......
......@@ -360,29 +360,20 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
source = source || 'keyboard';
const positions = this._cursors.getPositions();
const primaryPosition = positions[0];
const viewPositions = this._cursors.getViewPositions();
const primaryViewPosition = viewPositions[0];
const secondaryViewPositions = viewPositions.slice(1);
let isInEditableRange: boolean = true;
if (this._model.hasEditableRange()) {
const editableRange = this._model.getEditableRange();
if (!editableRange.containsPosition(primaryPosition)) {
if (!editableRange.containsPosition(positions[0])) {
isInEditableRange = false;
}
}
const selections = this._cursors.getSelections();
const viewSelections = this._cursors.getViewSelections();
const primaryViewSelection = viewSelections[0];
const secondaryViewSelections = viewSelections.slice(1);
this._onDidChange.fire(new CursorStateChangedEvent(selections, source, reason));
this._emit([new viewEvents.ViewCursorPositionChangedEvent(primaryViewPosition, secondaryViewPositions, isInEditableRange)]);
this._emit([new viewEvents.ViewCursorSelectionChangedEvent(primaryViewSelection, secondaryViewSelections)]);
this._emit([new viewEvents.ViewCursorStateChangedEvent(viewSelections, isInEditableRange)]);
}
private _revealRange(revealTarget: RevealTarget, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean): void {
......
......@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { ScrollEvent } from 'vs/base/common/scrollable';
......@@ -14,21 +13,20 @@ import { IDisposable, Disposable } from "vs/base/common/lifecycle";
export const enum ViewEventType {
ViewConfigurationChanged = 1,
ViewCursorPositionChanged = 2,
ViewCursorSelectionChanged = 3,
ViewDecorationsChanged = 4,
ViewFlushed = 5,
ViewFocusChanged = 6,
ViewLineMappingChanged = 7,
ViewLinesChanged = 8,
ViewLinesDeleted = 9,
ViewLinesInserted = 10,
ViewRevealRangeRequest = 11,
ViewScrollChanged = 12,
ViewTokensChanged = 13,
ViewTokensColorsChanged = 14,
ViewZonesChanged = 15,
ViewThemeChanged = 16
ViewCursorStateChanged = 2,
ViewDecorationsChanged = 3,
ViewFlushed = 4,
ViewFocusChanged = 5,
ViewLineMappingChanged = 6,
ViewLinesChanged = 7,
ViewLinesDeleted = 8,
ViewLinesInserted = 9,
ViewRevealRangeRequest = 10,
ViewScrollChanged = 11,
ViewTokensChanged = 12,
ViewTokensColorsChanged = 13,
ViewZonesChanged = 14,
ViewThemeChanged = 15
}
export class ViewConfigurationChangedEvent {
......@@ -60,49 +58,25 @@ export class ViewConfigurationChangedEvent {
}
}
export class ViewCursorPositionChangedEvent {
export class ViewCursorStateChangedEvent {
public readonly type = ViewEventType.ViewCursorPositionChanged;
public readonly type = ViewEventType.ViewCursorStateChanged;
/**
* Primary cursor's position.
* The primary selection is always at index 0.
*/
public readonly position: Position;
/**
* Secondary cursors' position.
*/
public readonly secondaryPositions: Position[];
public readonly selections: Selection[];
/**
* Is the primary cursor in the editable range?
*/
public readonly isInEditableRange: boolean;
constructor(position: Position, secondaryPositions: Position[], isInEditableRange: boolean) {
this.position = position;
this.secondaryPositions = secondaryPositions;
constructor(selections: Selection[], isInEditableRange: boolean) {
this.selections = selections;
this.isInEditableRange = isInEditableRange;
}
}
export class ViewCursorSelectionChangedEvent {
public readonly type = ViewEventType.ViewCursorSelectionChanged;
/**
* The primary selection.
*/
public readonly selection: Selection;
/**
* The secondary selections.
*/
public readonly secondarySelections: Selection[];
constructor(selection: Selection, secondarySelections: Selection[]) {
this.selection = selection;
this.secondarySelections = secondarySelections;
}
}
export class ViewDecorationsChangedEvent {
public readonly type = ViewEventType.ViewDecorationsChanged;
......@@ -304,8 +278,7 @@ export class ViewZonesChangedEvent {
export type ViewEvent = (
ViewConfigurationChangedEvent
| ViewCursorPositionChangedEvent
| ViewCursorSelectionChangedEvent
| ViewCursorStateChangedEvent
| ViewDecorationsChangedEvent
| ViewFlushedEvent
| ViewFocusChangedEvent
......
......@@ -37,10 +37,7 @@ export class ViewEventHandler extends Disposable {
public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {
return false;
}
public onCursorPositionChanged(e: viewEvents.ViewCursorPositionChangedEvent): boolean {
return false;
}
public onCursorSelectionChanged(e: viewEvents.ViewCursorSelectionChangedEvent): boolean {
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
return false;
}
public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean {
......@@ -100,14 +97,8 @@ export class ViewEventHandler extends Disposable {
}
break;
case viewEvents.ViewEventType.ViewCursorPositionChanged:
if (this.onCursorPositionChanged(e)) {
shouldRender = true;
}
break;
case viewEvents.ViewEventType.ViewCursorSelectionChanged:
if (this.onCursorSelectionChanged(e)) {
case viewEvents.ViewEventType.ViewCursorStateChanged:
if (this.onCursorStateChanged(e)) {
shouldRender = true;
}
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册