@@ -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' ;
@@ -763,29 +763,13 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
763
763
protected override _doLayout ( heightInPixel : number ) : void {
764
764
765
765
const info = this . editor . getLayoutInfo ( ) ;
766
- const spaceLeft = info . lineNumbersWidth + info . glyphMarginWidth + info . decorationsWidth + ( this . _findApproximateIndentationWidth ( ) ?? 0 ) ;
767
- const spaceRight = info . minimap . minimapWidth + info . verticalScrollbarWidth ;
768
-
769
766
const maxWidth = ! this . widget . showsAnyPreview ( ) ? 640 : Number . MAX_SAFE_INTEGER ;
770
767
const width = Math . min ( maxWidth , info . contentWidth - ( info . glyphMarginWidth + info . decorationsWidth ) ) ;
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
778
- private _findApproximateIndentationWidth ( ) : number | undefined {
779
- if ( ! this . position ) {
780
- return ;
781
- }
782
- const lineIndentColumn = this . editor . _getViewModel ( ) ?. getLineIndentColumn ( this . position . lineNumber ) ;
783
- if ( ! lineIndentColumn ) {
784
- return ;
785
- }
786
- return ( lineIndentColumn - 1 ) * this . editor . getOption ( EditorOption . fontSize ) ;
787
- }
788
-
789
773
private _computeHeightInLines ( ) : number {
790
774
const lineHeight = this . editor . getOption ( EditorOption . lineHeight ) ;
791
775
return this . widget . getHeight ( ) / lineHeight ;
@@ -798,10 +782,30 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
798
782
super . _relayout ( this . _computeHeightInLines ( ) ) ;
799
783
}
800
784
801
- override show ( where : IPosition ) : void {
802
- super . show ( where , this . _computeHeightInLines ( ) ) ;
785
+ override show ( selectionRange : Range ) : void {
786
+ super . show ( selectionRange . getEndPosition ( ) , this . _computeHeightInLines ( ) ) ;
803
787
this . widget . focus ( ) ;
804
788
this . _ctxVisible . set ( true ) ;
789
+ this . _setMargins ( selectionRange ) ;
790
+ }
791
+
792
+ private _setMargins ( selectionRange : Range ) : void {
793
+ const info = this . editor . getLayoutInfo ( ) ;
794
+ const startLineNumber = selectionRange . getStartPosition ( ) . lineNumber ;
795
+ const endLineNumber = selectionRange . getEndPosition ( ) . lineNumber ;
796
+ let lineNumberForIndentation = endLineNumber ;
797
+ for ( let lineNumber = endLineNumber ; lineNumber >= startLineNumber ; lineNumber -- ) {
798
+ const lineContent = this . editor . getModel ( ) ?. getLineContent ( lineNumber ) ;
799
+ if ( lineContent !== '' ) {
800
+ lineNumberForIndentation = lineNumber ;
801
+ break ;
802
+ }
803
+ }
804
+ const indentationLevel = this . editor . _getViewModel ( ) ?. getLineFirstNonWhitespaceColumn ( lineNumberForIndentation ) ;
805
+ const spaceLeft = info . lineNumbersWidth + info . glyphMarginWidth + info . decorationsWidth + ( indentationLevel ? this . editor . getOffsetForColumn ( lineNumberForIndentation , indentationLevel ) : 0 ) ;
806
+ const spaceRight = info . minimap . minimapWidth + info . verticalScrollbarWidth ;
807
+ this . widget . domNode . style . marginLeft = `${ spaceLeft } px` ;
808
+ this . widget . domNode . style . marginRight = `${ spaceRight } px` ;
805
809
}
806
810
807
811
override hide ( ) : void {
0 commit comments