Skip to content

Commit 3b7d859

Browse files
authored
1 parent ee1e743 commit 3b7d859

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { localize } from 'vs/nls';
1212
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1313
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1414
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/browser/zoneWidget';
15-
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_VISIBLE, MENU_INLINE_CHAT_WIDGET, MENU_INLINE_CHAT_WIDGET_STATUS, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, CTX_INLINE_CHAT_MESSAGE_CROP_STATE, IInlineChatSlashCommand, MENU_INLINE_CHAT_WIDGET_FEEDBACK, ACTION_REGENERATE_RESPONSE, ACTION_VIEW_IN_CHAT, MENU_INLINE_CHAT_WIDGET_TOGGLE } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
15+
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_VISIBLE, MENU_INLINE_CHAT_WIDGET, MENU_INLINE_CHAT_WIDGET_STATUS, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, CTX_INLINE_CHAT_MESSAGE_CROP_STATE, IInlineChatSlashCommand, MENU_INLINE_CHAT_WIDGET_FEEDBACK, ACTION_REGENERATE_RESPONSE, ACTION_VIEW_IN_CHAT, MENU_INLINE_CHAT_WIDGET_TOGGLE, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
1616
import { IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
1717
import { EventType, Dimension, addDisposableListener, getActiveElement, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
1818
import { Emitter, Event, MicrotaskEmitter } from 'vs/base/common/event';
@@ -234,9 +234,24 @@ export class InlineChatWidget {
234234

235235
// (1) inner cursor position (last/first line selected)
236236
const updateInnerCursorFirstLast = () => {
237-
const { lineNumber } = this._inputEditor.getPosition();
238-
this._ctxInnerCursorFirst.set(lineNumber === 1);
239-
this._ctxInnerCursorLast.set(lineNumber === this._inputModel.getLineCount());
237+
const selection = this._inputEditor.getSelection();
238+
let onFirst = false;
239+
let onLast = false;
240+
if (selection.isEmpty()) {
241+
const selectionTop = this._inputEditor.getTopForPosition(selection.startLineNumber, selection.startColumn);
242+
const fullRange = this._inputModel.getFullModelRange();
243+
const firstViewLineTop = this._inputEditor.getTopForPosition(fullRange.startLineNumber, fullRange.startColumn);
244+
const lastViewLineTop = this._inputEditor.getTopForPosition(fullRange.endLineNumber, fullRange.endColumn);
245+
246+
if (selectionTop === firstViewLineTop) {
247+
onFirst = true;
248+
}
249+
if (selectionTop === lastViewLineTop) {
250+
onLast = true;
251+
}
252+
}
253+
this._ctxInnerCursorFirst.set(onFirst);
254+
this._ctxInnerCursorLast.set(onLast);
240255
};
241256
this._store.add(this._inputEditor.onDidChangeCursorPosition(updateInnerCursorFirstLast));
242257
updateInnerCursorFirstLast();

0 commit comments

Comments
 (0)