Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Block cursor be on inlay hint #226515

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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 '../cursorCommon.js';
import { CursorConfiguration, CursorState, ICursorSimpleModel, SelectionStartKind, SingleCursorState } from '../cursorCommon.js';
import { CursorContext } from './cursorContext.js';
import { Position } from '../core/position.js';
import { Range } from '../core/range.js';
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.RightOfInjectedTextBlockCursor : 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
20 changes: 19 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 './config/editorOptions.js';
import { ConfigurationChangedEvent, EditorAutoClosingEditStrategy, EditorAutoClosingStrategy, EditorAutoIndentStrategy, EditorAutoSurroundStrategy, EditorOption, TextEditorCursorStyle } from './config/editorOptions.js';
import { LineTokens } from './tokens/lineTokens.js';
import { Position } from './core/position.js';
import { Range } from './core/range.js';
Expand Down Expand Up @@ -83,6 +83,21 @@ 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 (
e.hasChanged(EditorOption.layoutInfo)
Expand All @@ -102,6 +117,7 @@ export class CursorConfiguration {
|| e.hasChanged(EditorOption.readOnly)
|| e.hasChanged(EditorOption.wordSegmenterLocales)
|| e.hasChanged(EditorOption.overtypeOnPaste)
|| e.hasChanged(EditorOption.cursorStyle)
);
}

Expand Down Expand Up @@ -145,6 +161,8 @@ export class CursorConfiguration {
this.surroundingPairs = {};
this._electricChars = null;

this.cursorStyle = options.get(EditorOption.cursorStyle);

this.shouldAutoCloseBefore = {
quote: this._getShouldAutoClose(languageId, this.autoClosingQuotes, true),
comment: this._getShouldAutoClose(languageId, this.autoClosingComments, false),
Expand Down
6 changes: 6 additions & 0 deletions src/vs/editor/common/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export enum InjectedTextCursorStops {
Both,
Right,
Left,
LeftIfNonBlockCursor,
None
}

Expand Down Expand Up @@ -1373,6 +1374,11 @@ export const enum PositionAffinity {
* If the given position is on injected text, prefers the position right of it.
*/
RightOfInjectedText = 4,

/**
* If the given position is on injected text while the cursor is block cursor, prefers the position right of it.
*/
RightOfInjectedTextBlockCursor = 5,
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/modelLineProjectionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ModelLineProjectionData {

return result;
}
} else if (affinity === PositionAffinity.Right || affinity === PositionAffinity.RightOfInjectedText) {
} else if (affinity === PositionAffinity.Right || affinity === PositionAffinity.RightOfInjectedText || affinity === PositionAffinity.RightOfInjectedTextBlockCursor) {
let result = injectedText.offsetInInputWithInjections + injectedText.length;
let index = injectedText.injectedTextIndex;
// traverse all injected text that touch each other
Expand Down
9 changes: 7 additions & 2 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ export enum InjectedTextCursorStops {
Both = 0,
Right = 1,
Left = 2,
None = 3
LeftIfNonBlockCursor = 3,
None = 4
}

export enum InlayHintKind {
Expand Down Expand Up @@ -800,7 +801,11 @@ export enum PositionAffinity {
/**
* If the given position is on injected text, prefers the position right of it.
*/
RightOfInjectedText = 4
RightOfInjectedText = 4,
/**
* If the given position is on injected text while the cursor is block cursor, prefers the position right of it.
*/
RightOfInjectedTextBlockCursor = 5
}

export enum RenderLineNumbersType {
Expand Down
9 changes: 7 additions & 2 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,8 @@ declare namespace monaco.editor {
Both = 0,
Right = 1,
Left = 2,
None = 3
LeftIfNonBlockCursor = 3,
None = 4
}

/**
Expand Down Expand Up @@ -2388,7 +2389,11 @@ declare namespace monaco.editor {
/**
* If the given position is on injected text, prefers the position right of it.
*/
RightOfInjectedText = 4
RightOfInjectedText = 4,
/**
* If the given position is on injected text while the cursor is block cursor, prefers the position right of it.
*/
RightOfInjectedTextBlockCursor = 5
}

/**
Expand Down