提交 1a404522 编写于 作者: P Peng Lyu

scrollOff ignoring single mouse clicking

上级 6829b316
......@@ -294,7 +294,7 @@ export namespace CoreNavigationCommands {
CursorMoveCommands.moveTo(cursors.context, cursors.getPrimaryCursor(), this._inSelectionMode, args.position, args.viewPosition)
]
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -322,7 +322,7 @@ export namespace CoreNavigationCommands {
toViewLineNumber: result.toLineNumber,
toViewVisualColumn: result.toVisualColumn
});
cursors.reveal(true, (result.reversed ? RevealTarget.TopMost : RevealTarget.BottomMost), ScrollType.Smooth);
cursors.reveal(args.source, true, (result.reversed ? RevealTarget.TopMost : RevealTarget.BottomMost), ScrollType.Smooth);
}
protected abstract _getColumnSelectResult(context: CursorContext, primary: CursorState, prevColumnSelectData: IColumnSelectData, args: any): IColumnSelectResult;
......@@ -492,7 +492,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
CursorMoveCommands.move(cursors.context, cursors.getAll(), args)
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -831,7 +831,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
CursorMoveCommands.moveToBeginningOfLine(cursors.context, cursors.getAll(), this._inSelectionMode)
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -880,7 +880,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
this._exec(cursors.context, cursors.getAll())
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
private _exec(context: CursorContext, cursors: CursorState[]): PartialCursorState[] {
......@@ -910,7 +910,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
CursorMoveCommands.moveToEndOfLine(cursors.context, cursors.getAll(), this._inSelectionMode)
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -959,7 +959,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
this._exec(cursors.context, cursors.getAll())
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
private _exec(context: CursorContext, cursors: CursorState[]): PartialCursorState[] {
......@@ -990,7 +990,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
CursorMoveCommands.moveToBeginningOfBuffer(cursors.context, cursors.getAll(), this._inSelectionMode)
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -1034,7 +1034,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
CursorMoveCommands.moveToEndOfBuffer(cursors.context, cursors.getAll(), this._inSelectionMode)
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -1253,7 +1253,7 @@ export namespace CoreNavigationCommands {
CursorMoveCommands.word(cursors.context, cursors.getPrimaryCursor(), this._inSelectionMode, args.position)
]
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -1313,7 +1313,7 @@ export namespace CoreNavigationCommands {
CursorMoveCommands.line(cursors.context, cursors.getPrimaryCursor(), this._inSelectionMode, args.position, args.viewPosition)
]
);
cursors.reveal(false, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, false, RevealTarget.Primary, ScrollType.Smooth);
}
}
......@@ -1385,7 +1385,7 @@ export namespace CoreNavigationCommands {
CursorChangeReason.Explicit,
CursorMoveCommands.expandLineSelection(cursors.context, cursors.getAll())
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
});
......@@ -1413,7 +1413,7 @@ export namespace CoreNavigationCommands {
CursorMoveCommands.cancelSelection(cursors.context, cursors.getPrimaryCursor())
]
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
});
......@@ -1440,7 +1440,7 @@ export namespace CoreNavigationCommands {
cursors.getPrimaryCursor()
]
);
cursors.reveal(true, RevealTarget.Primary, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.Primary, ScrollType.Smooth);
}
});
......@@ -1488,7 +1488,7 @@ export namespace CoreNavigationCommands {
const viewRange = cursors.context.convertModelRangeToViewRange(range);
cursors.revealRange(false, viewRange, revealAt, ScrollType.Smooth);
cursors.revealRange(args.source, false, viewRange, revealAt, ScrollType.Smooth);
}
});
......
......@@ -280,6 +280,7 @@ export class TextAreaHandler extends ViewPart {
const column = this._selections[0].startColumn;
this._context.privateViewEventBus.emit(new viewEvents.ViewRevealRangeRequestEvent(
'keyboard',
new Range(lineNumber, column, lineNumber, column),
viewEvents.VerticalRevealType.Simple,
true,
......
......@@ -12,6 +12,7 @@ import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/v
import { DomReadingContext, ViewLine, ViewLineOptions } from 'vs/editor/browser/viewParts/lines/viewLine';
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 { ScrollType } from 'vs/editor/common/editorCommon';
import { HorizontalRange, IViewLines, LineVisibleRanges } from 'vs/editor/common/view/renderingContext';
import { ViewContext } from 'vs/editor/common/view/viewContext';
......@@ -71,6 +72,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
private _typicalHalfwidthCharacterWidth: number;
private _isViewportWrapping: boolean;
private _revealHorizontalRightPadding: number;
private _selections: Selection[];
private _scrollOff: number;
private _canUseLayerHinting: boolean;
private _viewLineOptions: ViewLineOptions;
......@@ -98,6 +100,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
this._scrollOff = conf.editor.viewInfo.cursorSurroundingLines;
this._canUseLayerHinting = conf.editor.canUseLayerHinting;
this._viewLineOptions = new ViewLineOptions(conf, this._context.theme.type);
this._selections = [];
PartFingerprints.write(this.domNode, PartFingerprint.ViewLines);
this.domNode.setClassName('view-lines');
......@@ -188,6 +191,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
return false;
}
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
this._selections = e.selections;
const rendStartLineNumber = this._visibleLines.getStartLineNumber();
const rendEndLineNumber = this._visibleLines.getEndLineNumber();
let r = false;
......@@ -223,7 +227,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
public onRevealRangeRequest(e: viewEvents.ViewRevealRangeRequestEvent): boolean {
// Using the future viewport here in order to handle multiple
// incoming reveal range requests that might all desire to be animated
const desiredScrollTop = this._computeScrollTopToRevealRange(this._context.viewLayout.getFutureViewport(), e.range, e.verticalType);
const desiredScrollTop = this._computeScrollTopToRevealRange(this._context.viewLayout.getFutureViewport(), e.source, e.range, e.verticalType);
// validate the new desired scroll top
let newScrollPosition = this._context.viewLayout.validateScrollPosition({ scrollTop: desiredScrollTop });
......@@ -589,7 +593,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
}
}
private _computeScrollTopToRevealRange(viewport: Viewport, range: Range, verticalType: viewEvents.VerticalRevealType): number {
private _computeScrollTopToRevealRange(viewport: Viewport, source: string, range: Range, verticalType: viewEvents.VerticalRevealType): number {
const viewportStartY = viewport.top;
const viewportHeight = viewport.height;
const viewportEndY = viewportStartY + viewportHeight;
......@@ -600,9 +604,16 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
boxStartY = this._context.viewLayout.getVerticalOffsetForLineNumber(range.startLineNumber);
boxEndY = this._context.viewLayout.getVerticalOffsetForLineNumber(range.endLineNumber) + this._lineHeight;
const context = Math.min((viewportHeight / this._lineHeight) / 2, this._scrollOff);
boxStartY -= context * this._lineHeight;
boxEndY += Math.max(0, (context - 1)) * this._lineHeight;
const shouldIgnoreScrollOff = source === 'mouse' && (
this._selections.length > 1 // scroll off might trigger scrolling and mess up with multi cursor
|| (this._selections.length > 0 && this._selections[0].isEmpty()) // we don't want to single click triggering selection
);
if (!shouldIgnoreScrollOff) {
const context = Math.min((viewportHeight / this._lineHeight) / 2, this._scrollOff);
boxStartY -= context * this._lineHeight;
boxEndY += Math.max(0, (context - 1)) * this._lineHeight;
}
if (verticalType === viewEvents.VerticalRevealType.Simple || verticalType === viewEvents.VerticalRevealType.Bottom) {
// Reveal one line more when the last line would be covered by the scrollbar - arrow down case or revealing a line explicitly at bottom
......
......@@ -517,6 +517,7 @@ export class Minimap extends ViewPart {
lineNumber = Math.min(lineNumber, this._context.model.getLineCount());
this._context.privateViewEventBus.emit(new viewEvents.ViewRevealRangeRequestEvent(
'mouse',
new Range(lineNumber, 1, lineNumber, 1),
viewEvents.VerticalRevealType.Center,
false,
......
......@@ -526,7 +526,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
const validatedModelRange = this._modelData.model.validateRange(modelRange);
const viewRange = this._modelData.viewModel.coordinatesConverter.convertModelRangeToViewRange(validatedModelRange);
this._modelData.cursor.emitCursorRevealRange(viewRange, verticalType, revealHorizontal, scrollType);
this._modelData.cursor.emitCursorRevealRange('api', viewRange, verticalType, revealHorizontal, scrollType);
}
public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
......
......@@ -295,12 +295,12 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._columnSelectData = columnSelectData;
}
public reveal(horizontal: boolean, target: RevealTarget, scrollType: editorCommon.ScrollType): void {
this._revealRange(target, viewEvents.VerticalRevealType.Simple, horizontal, scrollType);
public reveal(source: string, horizontal: boolean, target: RevealTarget, scrollType: editorCommon.ScrollType): void {
this._revealRange(source, target, viewEvents.VerticalRevealType.Simple, horizontal, scrollType);
}
public revealRange(revealHorizontal: boolean, viewRange: Range, verticalType: viewEvents.VerticalRevealType, scrollType: editorCommon.ScrollType) {
this.emitCursorRevealRange(viewRange, verticalType, revealHorizontal, scrollType);
public revealRange(source: string, revealHorizontal: boolean, viewRange: Range, verticalType: viewEvents.VerticalRevealType, scrollType: editorCommon.ScrollType) {
this.emitCursorRevealRange(source, viewRange, verticalType, revealHorizontal, scrollType);
}
public scrollTo(desiredScrollTop: number): void {
......@@ -371,7 +371,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}
this.setStates('restoreState', CursorChangeReason.NotSet, CursorState.fromModelSelections(desiredSelections));
this.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Immediate);
this.reveal('restoreState', true, RevealTarget.Primary, editorCommon.ScrollType.Immediate);
}
private _onModelContentChanged(hadFlushEvent: boolean): void {
......@@ -543,7 +543,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return true;
}
private _revealRange(revealTarget: RevealTarget, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
private _revealRange(source: string, revealTarget: RevealTarget, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
const viewPositions = this._cursors.getViewPositions();
let viewPosition = viewPositions[0];
......@@ -568,13 +568,13 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column);
this.emitCursorRevealRange(viewRange, verticalType, revealHorizontal, scrollType);
this.emitCursorRevealRange(source, viewRange, verticalType, revealHorizontal, scrollType);
}
public emitCursorRevealRange(viewRange: Range, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) {
public emitCursorRevealRange(source: string, viewRange: Range, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) {
try {
const eventsCollector = this._beginEmit();
eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(viewRange, verticalType, revealHorizontal, scrollType));
eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, verticalType, revealHorizontal, scrollType));
} finally {
this._endEmit();
}
......@@ -748,7 +748,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._validateAutoClosedActions();
if (this._emitStateChangedIfNecessary(source, cursorChangeReason, oldState)) {
this._revealRange(RevealTarget.Primary, viewEvents.VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth);
this._revealRange(source, RevealTarget.Primary, viewEvents.VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth);
}
}
......
......@@ -55,8 +55,8 @@ export interface ICursors {
setColumnSelectData(columnSelectData: IColumnSelectData): void;
setStates(source: string, reason: CursorChangeReason, states: PartialCursorState[] | null): void;
reveal(horizontal: boolean, target: RevealTarget, scrollType: ScrollType): void;
revealRange(revealHorizontal: boolean, viewRange: Range, verticalType: VerticalRevealType, scrollType: ScrollType): void;
reveal(source: string, horizontal: boolean, target: RevealTarget, scrollType: ScrollType): void;
revealRange(source: string, revealHorizontal: boolean, viewRange: Range, verticalType: VerticalRevealType, scrollType: ScrollType): void;
scrollTo(desiredScrollTop: number): void;
......
......@@ -198,7 +198,13 @@ export class ViewRevealRangeRequestEvent {
public readonly scrollType: ScrollType;
constructor(range: Range, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: ScrollType) {
/**
* Source of the call that caused the event.
*/
readonly source: string;
constructor(source: string, range: Range, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: ScrollType) {
this.source = source;
this.range = range;
this.verticalType = verticalType;
this.revealHorizontal = revealHorizontal;
......
......@@ -72,7 +72,7 @@ export class InsertCursorAbove extends EditorAction {
CursorChangeReason.Explicit,
CursorMoveCommands.addCursorUp(context, cursors.getAll(), useLogicalLine)
);
cursors.reveal(true, RevealTarget.TopMost, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.TopMost, ScrollType.Smooth);
}
}
......@@ -121,7 +121,7 @@ export class InsertCursorBelow extends EditorAction {
CursorChangeReason.Explicit,
CursorMoveCommands.addCursorDown(context, cursors.getAll(), useLogicalLine)
);
cursors.reveal(true, RevealTarget.BottomMost, ScrollType.Smooth);
cursors.reveal(args.source, true, RevealTarget.BottomMost, ScrollType.Smooth);
}
}
......@@ -1053,4 +1053,4 @@ registerEditorAction(MoveSelectionToPreviousFindMatchAction);
registerEditorAction(SelectHighlightsAction);
registerEditorAction(CompatChangeAll);
registerEditorAction(InsertCursorAtEndOfLineSelected);
registerEditorAction(InsertCursorAtTopOfLineSelected);
\ No newline at end of file
registerEditorAction(InsertCursorAtTopOfLineSelected);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册