@@ -26,7 +26,7 @@ import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/br
26
26
import { HiddenItemStrategy , MenuWorkbenchToolBar } from 'vs/platform/actions/browser/toolbar' ;
27
27
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar' ;
28
28
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController' ;
29
- import { IPosition , Position } from 'vs/editor/common/core/position' ;
29
+ import { Position } from 'vs/editor/common/core/position' ;
30
30
import { DEFAULT_FONT_FAMILY } from 'vs/workbench/browser/style' ;
31
31
import { DropdownWithDefaultActionViewItem , IMenuEntryActionViewItemOptions , MenuEntryActionViewItem , createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
32
32
import { CompletionItem , CompletionItemInsertTextRule , CompletionItemKind , CompletionItemProvider , CompletionList , ProviderResult , TextEdit } from 'vs/editor/common/languages' ;
@@ -720,6 +720,7 @@ export class InlineChatZoneWidget extends ZoneWidget {
720
720
private readonly _ctxVisible : IContextKey < boolean > ;
721
721
private readonly _ctxCursorPosition : IContextKey < 'above' | 'below' | '' > ;
722
722
private _dimension ?: Dimension ;
723
+ private _indentationWidth : number = 0 ;
723
724
724
725
constructor (
725
726
editor : ICodeEditor ,
@@ -766,19 +767,18 @@ export class InlineChatZoneWidget extends ZoneWidget {
766
767
767
768
protected override _doLayout ( heightInPixel : number ) : void {
768
769
769
- const info = this . editor . getLayoutInfo ( ) ;
770
- const spaceLeft = info . lineNumbersWidth + info . glyphMarginWidth + info . decorationsWidth ;
771
- const spaceRight = info . minimap . minimapWidth + info . verticalScrollbarWidth ;
772
-
773
770
const maxWidth = ! this . widget . showsAnyPreview ( ) ? 640 : Number . MAX_SAFE_INTEGER ;
774
- const width = Math . min ( maxWidth , info . contentWidth - ( info . glyphMarginWidth + info . decorationsWidth ) ) ;
771
+ const width = Math . min ( maxWidth , this . _availableSpaceGivenIndentation ( ) ) ;
775
772
this . _dimension = new Dimension ( width , heightInPixel ) ;
776
- this . widget . domNode . style . marginLeft = `${ spaceLeft } px` ;
777
- this . widget . domNode . style . marginRight = `${ spaceRight } px` ;
778
773
this . widget . domNode . style . width = `${ width } px` ;
779
774
this . widget . layout ( this . _dimension ) ;
780
775
}
781
776
777
+ private _availableSpaceGivenIndentation ( ) : number {
778
+ const info = this . editor . getLayoutInfo ( ) ;
779
+ return info . contentWidth - ( info . glyphMarginWidth + info . decorationsWidth + this . _indentationWidth ) ;
780
+ }
781
+
782
782
private _computeHeightInLines ( ) : number {
783
783
const lineHeight = this . editor . getOption ( EditorOption . lineHeight ) ;
784
784
return this . widget . getHeight ( ) / lineHeight ;
@@ -791,10 +791,41 @@ export class InlineChatZoneWidget extends ZoneWidget {
791
791
super . _relayout ( this . _computeHeightInLines ( ) ) ;
792
792
}
793
793
794
- override show ( where : IPosition ) : void {
795
- super . show ( where , this . _computeHeightInLines ( ) ) ;
794
+ override show ( position : Position ) : void {
795
+ super . show ( position , this . _computeHeightInLines ( ) ) ;
796
796
this . widget . focus ( ) ;
797
797
this . _ctxVisible . set ( true ) ;
798
+ this . _setMargins ( position ) ;
799
+ }
800
+
801
+ private _setMargins ( position : Position ) : void {
802
+ const viewModel = this . editor . _getViewModel ( ) ;
803
+ if ( ! viewModel ) {
804
+ return ;
805
+ }
806
+ const visibleRange = viewModel . getCompletelyVisibleViewRange ( ) ;
807
+ const startLineVisibleRange = visibleRange . startLineNumber ;
808
+ const positionLine = position . lineNumber ;
809
+ let indentationLineNumber : number | undefined ;
810
+ let indentationLevel : number | undefined ;
811
+ for ( let lineNumber = positionLine ; lineNumber >= startLineVisibleRange ; lineNumber -- ) {
812
+ const currentIndentationLevel = viewModel . getLineFirstNonWhitespaceColumn ( lineNumber ) ;
813
+ if ( currentIndentationLevel !== 0 ) {
814
+ indentationLineNumber = lineNumber ;
815
+ indentationLevel = currentIndentationLevel ;
816
+ break ;
817
+ }
818
+ }
819
+ this . _indentationWidth = this . editor . getOffsetForColumn ( indentationLineNumber ?? positionLine , indentationLevel ?? viewModel . getLineFirstNonWhitespaceColumn ( positionLine ) ) ;
820
+ const info = this . editor . getLayoutInfo ( ) ;
821
+ const marginWithoutIndentation = info . glyphMarginWidth + info . decorationsWidth + info . lineNumbersWidth ;
822
+ const marginWithIndentation = marginWithoutIndentation + this . _indentationWidth ;
823
+ const isEnoughAvailableSpaceWithIndentation = this . _availableSpaceGivenIndentation ( ) > 400 ;
824
+ this . _indentationWidth = isEnoughAvailableSpaceWithIndentation ? this . _indentationWidth : 0 ;
825
+ const spaceLeft = isEnoughAvailableSpaceWithIndentation ? marginWithIndentation : marginWithoutIndentation ;
826
+ const spaceRight = info . minimap . minimapWidth + info . verticalScrollbarWidth ;
827
+ this . widget . domNode . style . marginLeft = `${ spaceLeft } px` ;
828
+ this . widget . domNode . style . marginRight = `${ spaceRight } px` ;
798
829
}
799
830
800
831
override hide ( ) : void {
0 commit comments