22import * as vscode from 'vscode' ;
33
44import { blueBorderTopDecoration , blueBorderBottomDecoration , greyBorderTopDecoration , greyBorderBottomDecoration , fontWeightBoldDecoration } from './Decorations' ;
5- import { SectionModel , SectionsData } from '../model/SectionModel'
5+ import { SectionModel , SectionsData , SectionData } from '../model/SectionModel'
66import { Disposer } from '../commandwindow/Utilities' ;
77import { StartAndEndLines , TopAndBottomRanges , StylingRanges } from './StylingInterfaces' ;
88let previousFocusedEditor : vscode . TextEditor | undefined ;
@@ -105,7 +105,8 @@ export class SectionStylingService extends Disposer {
105105 */
106106 private _highlightSections ( editor : vscode . TextEditor , sections : SectionsData , activeCursorPosition : vscode . Position | null ) : void {
107107 const startAndEndLines = this . _sectionsToStartAndEndLines ( sections . sectionRanges ) ;
108- const allStartLinesRange = this . _generateRanges ( startAndEndLines . startLines ) ;
108+ const explicitStartAndEndLines = this . _sectionsToStartAndEndLines ( sections . sectionRanges . filter ( ( section ) => section . isExplicit ) ) ;
109+ const explicitSectionRanges = this . _generateRanges ( explicitStartAndEndLines . startLines ) ;
109110 const lastLineinSection = startAndEndLines . endLines . sort ( ( a , b ) => a - b ) [ startAndEndLines . endLines . length - 1 ] ;
110111
111112 let stylingRanges : StylingRanges ;
@@ -114,9 +115,9 @@ export class SectionStylingService extends Disposer {
114115 if ( cursorPositionLine > lastLineinSection ) {
115116 cursorPositionLine = lastLineinSection
116117 }
117- const focusedSectionRange : vscode . Range | undefined = this . _findFocusedSectionRange ( sections , cursorPositionLine ) ;
118- if ( focusedSectionRange !== undefined ) {
119- stylingRanges = this . _getBlueAndGreyRanges ( startAndEndLines , focusedSectionRange ) ;
118+ const focusedSection = this . _findFocusedSection ( sections , cursorPositionLine ) ;
119+ if ( focusedSection !== undefined ) {
120+ stylingRanges = this . _getBlueAndGreyRanges ( startAndEndLines , focusedSection ) ;
120121 } else {
121122 stylingRanges = { blue : { top : [ ] , bottom : [ ] } , grey : this . _getGreyRanges ( startAndEndLines ) } ;
122123 }
@@ -125,12 +126,12 @@ export class SectionStylingService extends Disposer {
125126 }
126127 this . _filterFirstAndLastSection ( stylingRanges , lastLineinSection , editor . document ) ;
127128
128- this . _setDecorations ( editor , stylingRanges , allStartLinesRange ) ;
129+ this . _setDecorations ( editor , stylingRanges , explicitSectionRanges ) ;
129130 }
130131
131- private _getBlueAndGreyRanges ( startAndEndLines : StartAndEndLines , focusedSectionRange : vscode . Range ) : StylingRanges {
132- const focusedStartLine = focusedSectionRange . start . line ;
133- const focusedEndLine = focusedSectionRange . end . line ;
132+ private _getBlueAndGreyRanges ( startAndEndLines : StartAndEndLines , focusedSectionRange : SectionData ) : StylingRanges {
133+ const focusedStartLine = focusedSectionRange . range . start . line ;
134+ const focusedEndLine = focusedSectionRange . range . end . line ;
134135 const { startLines, endLines } = startAndEndLines ;
135136
136137 const startLinesWithoutFocusLine = startLines . filter ( ( startLine ) => {
@@ -181,32 +182,32 @@ export class SectionStylingService extends Disposer {
181182 return { top : this . _generateRanges ( startLines ) , bottom : this . _generateRanges ( endLinesFiltered ) } ;
182183 }
183184
184- private _setDecorations ( editor : vscode . TextEditor , stylingRange : StylingRanges , allStartLinesRange : vscode . Range [ ] ) : void {
185+ private _setDecorations ( editor : vscode . TextEditor , stylingRange : StylingRanges , explicitSectionRanges : vscode . Range [ ] ) : void {
185186 editor . setDecorations ( blueBorderTopDecoration , stylingRange . blue . top ) ;
186187 editor . setDecorations ( blueBorderBottomDecoration , stylingRange . blue . bottom ) ;
187188 editor . setDecorations ( greyBorderTopDecoration , stylingRange . grey . top ) ;
188189 editor . setDecorations ( greyBorderBottomDecoration , stylingRange . grey . bottom ) ;
189- editor . setDecorations ( fontWeightBoldDecoration , allStartLinesRange ) ;
190+ editor . setDecorations ( fontWeightBoldDecoration , explicitSectionRanges ) ;
190191 }
191192
192193 private _generateRanges ( lines : number [ ] ) : vscode . Range [ ] {
193194 return lines . map ( ( line : number ) => new vscode . Range ( line , 0 , line , Infinity ) ) ;
194195 }
195196
196- private _findFocusedSectionRange ( sections : SectionsData , lineNumber : number ) : vscode . Range | undefined {
197- let activeSection : vscode . Range | undefined ;
197+ private _findFocusedSection ( sections : SectionsData , lineNumber : number ) : SectionData | undefined {
198+ let activeSection : SectionData | undefined ;
198199 if ( lineNumber !== undefined && sections . sectionsTree !== undefined ) {
199200 activeSection = sections . sectionsTree . find ( lineNumber ) ;
200201 }
201202 return activeSection ;
202203 }
203204
204- private _sectionsToStartAndEndLines ( sectionRanges : vscode . Range [ ] ) : StartAndEndLines {
205+ private _sectionsToStartAndEndLines ( sectionRanges : SectionData [ ] ) : StartAndEndLines {
205206 const startLines = new Set < number > ( ) ;
206207 const endLines = new Set < number > ( ) ;
207- sectionRanges . forEach ( ( sectionRange : vscode . Range ) => {
208- const startingIndex = sectionRange . start . line ;
209- const endingIndex = sectionRange . end . line ;
208+ sectionRanges . forEach ( ( sectionRange : SectionData ) => {
209+ const startingIndex = sectionRange . range . start . line ;
210+ const endingIndex = sectionRange . range . end . line ;
210211 startLines . add ( startingIndex ) ;
211212 endLines . add ( endingIndex ) ;
212213 } ) ;
0 commit comments