@@ -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' ;
@@ -716,6 +716,7 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
716
716
private readonly _ctxVisible : IContextKey < boolean > ;
717
717
private readonly _ctxCursorPosition : IContextKey < 'above' | 'below' | '' > ;
718
718
private _dimension ?: Dimension ;
719
+ private _indentationWidth : number = 0 ;
719
720
720
721
constructor (
721
722
editor : ICodeEditor ,
@@ -762,19 +763,18 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
762
763
763
764
protected override _doLayout ( heightInPixel : number ) : void {
764
765
765
- const info = this . editor . getLayoutInfo ( ) ;
766
- const spaceLeft = info . lineNumbersWidth + info . glyphMarginWidth + info . decorationsWidth ;
767
- const spaceRight = info . minimap . minimapWidth + info . verticalScrollbarWidth ;
768
-
769
766
const maxWidth = ! this . widget . showsAnyPreview ( ) ? 640 : Number . MAX_SAFE_INTEGER ;
770
- const width = Math . min ( maxWidth , info . contentWidth - ( info . glyphMarginWidth + info . decorationsWidth ) ) ;
767
+ const width = Math . min ( maxWidth , this . _availableSpaceGivenIndentation ( ) ) ;
771
768
this . _dimension = new Dimension ( width , heightInPixel ) ;
772
- this . widget . domNode . style . marginLeft = `${ spaceLeft } px` ;
773
- this . widget . domNode . style . marginRight = `${ spaceRight } px` ;
774
769
this . widget . domNode . style . width = `${ width } px` ;
775
770
this . widget . layout ( this . _dimension ) ;
776
771
}
777
772
773
+ private _availableSpaceGivenIndentation ( ) : number {
774
+ const info = this . editor . getLayoutInfo ( ) ;
775
+ return info . contentWidth - ( info . glyphMarginWidth + info . decorationsWidth + this . _indentationWidth ) ;
776
+ }
777
+
778
778
private _computeHeightInLines ( ) : number {
779
779
const lineHeight = this . editor . getOption ( EditorOption . lineHeight ) ;
780
780
return this . widget . getHeight ( ) / lineHeight ;
@@ -787,10 +787,40 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
787
787
super . _relayout ( this . _computeHeightInLines ( ) ) ;
788
788
}
789
789
790
- override show ( where : IPosition ) : void {
791
- super . show ( where , this . _computeHeightInLines ( ) ) ;
790
+ override show ( selectionRange : Range ) : void {
791
+ super . show ( selectionRange . getEndPosition ( ) , this . _computeHeightInLines ( ) ) ;
792
792
this . widget . focus ( ) ;
793
793
this . _ctxVisible . set ( true ) ;
794
+ this . _setMargins ( selectionRange ) ;
795
+ }
796
+
797
+ private _setMargins ( selectionRange : Range ) : void {
798
+ const info = this . editor . getLayoutInfo ( ) ;
799
+ const startLineNumber = selectionRange . getStartPosition ( ) . lineNumber ;
800
+ const endLineNumber = selectionRange . getEndPosition ( ) . lineNumber ;
801
+ const viewModel = this . editor . _getViewModel ( ) ;
802
+ if ( ! viewModel ) {
803
+ return ;
804
+ }
805
+ let indentationLineNumber ;
806
+ let indentationLevel ;
807
+ for ( let lineNumber = endLineNumber ; lineNumber >= startLineNumber ; lineNumber -- ) {
808
+ const currentIndentationLevel = viewModel . getLineFirstNonWhitespaceColumn ( lineNumber ) ;
809
+ if ( currentIndentationLevel !== 0 ) {
810
+ indentationLineNumber = lineNumber ;
811
+ indentationLevel = currentIndentationLevel ;
812
+ break ;
813
+ }
814
+ }
815
+ this . _indentationWidth = this . editor . getOffsetForColumn ( indentationLineNumber ?? endLineNumber , indentationLevel ?? viewModel . getLineFirstNonWhitespaceColumn ( endLineNumber ) ) ;
816
+ const marginWithoutIndentation = info . glyphMarginWidth + info . decorationsWidth + info . lineNumbersWidth ;
817
+ const marginWithIndentation = marginWithoutIndentation + this . _indentationWidth ;
818
+ const isEnoughAvailableSpaceWithIndentation = this . _availableSpaceGivenIndentation ( ) > 400 ;
819
+ this . _indentationWidth = isEnoughAvailableSpaceWithIndentation ? this . _indentationWidth : 0 ;
820
+ const spaceLeft = isEnoughAvailableSpaceWithIndentation ? marginWithIndentation : marginWithoutIndentation ;
821
+ const spaceRight = info . minimap . minimapWidth + info . verticalScrollbarWidth ;
822
+ this . widget . domNode . style . marginLeft = `${ spaceLeft } px` ;
823
+ this . widget . domNode . style . marginRight = `${ spaceRight } px` ;
794
824
}
795
825
796
826
override hide ( ) : void {
0 commit comments