Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet authored May 27, 2024
1 parent c70ad34 commit e9a5733
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/vs/editor/common/cursor/oneCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { CursorState, ICursorSimpleModel, SelectionStartKind, SingleCursorState } from 'vs/editor/common/cursorCommon';
import { CursorConfiguration, CursorState, ICursorSimpleModel, SelectionStartKind, SingleCursorState } from 'vs/editor/common/cursorCommon';
import { CursorContext } from 'vs/editor/common/cursor/cursorContext';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
Expand Down Expand Up @@ -88,12 +88,12 @@ export class Cursor {
return viewModel.normalizePosition(position, PositionAffinity.None);
}

private static _validateViewState(viewModel: ICursorSimpleModel, viewState: SingleCursorState): SingleCursorState {
private static _validateViewState(viewModel: ICursorSimpleModel, viewState: SingleCursorState, cursorConfig: CursorConfiguration): SingleCursorState {
const position = viewState.position;
const sStartPosition = viewState.selectionStart.getStartPosition();
const sEndPosition = viewState.selectionStart.getEndPosition();

const validPosition = viewModel.normalizePosition(position, PositionAffinity.None);
const validPosition = viewModel.normalizePosition(position, cursorConfig.cursorStyleKind === 'onCharacter' ? PositionAffinity.Right : PositionAffinity.None);
const validSStartPosition = this._validatePositionWithCache(viewModel, sStartPosition, position, validPosition);
const validSEndPosition = this._validatePositionWithCache(viewModel, sEndPosition, sStartPosition, validSStartPosition);

Expand All @@ -113,7 +113,7 @@ export class Cursor {

private _setState(context: CursorContext, modelState: SingleCursorState | null, viewState: SingleCursorState | null): void {
if (viewState) {
viewState = Cursor._validateViewState(context.viewModel, viewState);
viewState = Cursor._validateViewState(context.viewModel, viewState, context.cursorConfig);
}

if (!modelState) {
Expand Down
18 changes: 17 additions & 1 deletion src/vs/editor/common/cursorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ConfigurationChangedEvent, EditorAutoClosingEditStrategy, EditorAutoClosingStrategy, EditorAutoIndentStrategy, EditorAutoSurroundStrategy, EditorOption } from 'vs/editor/common/config/editorOptions';
import { ConfigurationChangedEvent, EditorAutoClosingEditStrategy, EditorAutoClosingStrategy, EditorAutoIndentStrategy, EditorAutoSurroundStrategy, EditorOption, TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
import { LineTokens } from 'vs/editor/common/tokens/lineTokens';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
Expand Down Expand Up @@ -80,6 +80,20 @@ export class CursorConfiguration {

private readonly _languageId: string;
private _electricChars: { [key: string]: boolean } | null;
public readonly cursorStyle: TextEditorCursorStyle;

public get cursorStyleKind(): 'beforeCharacter' | 'onCharacter' {
switch (this.cursorStyle) {
case TextEditorCursorStyle.Line:
case TextEditorCursorStyle.LineThin:
return 'beforeCharacter';
case TextEditorCursorStyle.Block:
case TextEditorCursorStyle.Underline:
case TextEditorCursorStyle.BlockOutline:
case TextEditorCursorStyle.UnderlineThin:
return 'onCharacter';
}
}

public static shouldRecreate(e: ConfigurationChangedEvent): boolean {
return (
Expand All @@ -99,6 +113,7 @@ export class CursorConfiguration {
|| e.hasChanged(EditorOption.fontInfo)
|| e.hasChanged(EditorOption.readOnly)
|| e.hasChanged(EditorOption.wordSegmenterLocales)
|| e.hasChanged(EditorOption.cursorStyle)
);
}

Expand Down Expand Up @@ -137,6 +152,7 @@ export class CursorConfiguration {
this.autoSurround = options.get(EditorOption.autoSurround);
this.autoIndent = options.get(EditorOption.autoIndent);
this.wordSegmenterLocales = options.get(EditorOption.wordSegmenterLocales);
this.cursorStyle = options.get(EditorOption.cursorStyle);

this.surroundingPairs = {};
this._electricChars = null;
Expand Down

0 comments on commit e9a5733

Please sign in to comment.