Skip to content

Commit

Permalink
fix: Block cursor be on inlay hint (#209417)
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed Aug 24, 2024
1 parent 6a6ce14 commit c4e5284
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 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.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 '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 @@ -81,6 +81,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 @@ -99,6 +114,7 @@ export class CursorConfiguration {
|| e.hasChanged(EditorOption.fontInfo)
|| e.hasChanged(EditorOption.readOnly)
|| e.hasChanged(EditorOption.wordSegmenterLocales)
|| e.hasChanged(EditorOption.cursorStyle)
);
}

Expand Down Expand Up @@ -141,6 +157,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
4 changes: 4 additions & 0 deletions src/vs/editor/common/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,10 @@ 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, 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
6 changes: 5 additions & 1 deletion src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,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, prefers the position right of it.
*/
RightOfInjectedTextBlockCursor = 5
}

export enum RenderLineNumbersType {
Expand Down
6 changes: 5 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,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, prefers the position right of it.
*/
RightOfInjectedTextBlockCursor = 5
}

/**
Expand Down

0 comments on commit c4e5284

Please sign in to comment.