Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Commit 6bbb541

Browse files
CrossRManuel Hornung
authored andcommitted
Extra Highlight/Cell info (#2566)
Hook up undercurl and special colour through to the ICell
1 parent 966fd2c commit 6bbb541

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

browser/src/neovim/NeovimInstance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ export class NeovimInstance extends EventEmitter implements INeovimInstance {
816816
!!highlightInfo.undercurl,
817817
highlightInfo.foreground,
818818
highlightInfo.background,
819+
highlightInfo.special,
819820
),
820821
)
821822
break

browser/src/neovim/Screen.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface IHighlight {
1414

1515
foregroundColor?: string
1616
backgroundColor?: string
17+
specialColor?: string
18+
1719
isItalicAvailable?: boolean
1820
isBoldAvailable?: boolean
1921
}
@@ -64,9 +66,12 @@ export interface ICell {
6466

6567
foregroundColor?: string
6668
backgroundColor?: string
69+
specialColor?: string
70+
6771
italic?: boolean
6872
bold?: boolean
6973
underline?: boolean
74+
undercurl?: boolean
7075
}
7176

7277
export interface IPixelPosition {
@@ -93,6 +98,7 @@ const DefaultCell: ICell = {
9398

9499
export class NeovimScreen implements IScreen {
95100
private _backgroundColor: string = "#000000"
101+
private _specialColor: string = "#000000"
96102
private _currentHighlight: IHighlight = {}
97103
private _cursorColumn: number = 0
98104
private _cursorRow: number = 0
@@ -161,6 +167,10 @@ export class NeovimScreen implements IScreen {
161167
return this._foregroundColor
162168
}
163169

170+
public get specialColor(): string {
171+
return this._specialColor
172+
}
173+
164174
public get currentForegroundColor(): string {
165175
return this._currentHighlight.foregroundColor || this._foregroundColor
166176
}
@@ -169,6 +179,10 @@ export class NeovimScreen implements IScreen {
169179
return this._currentHighlight.backgroundColor || this._backgroundColor
170180
}
171181

182+
public get currentSpecialColor(): string {
183+
return this._currentHighlight.specialColor || this._specialColor
184+
}
185+
172186
public getCell = (x: number, y: number) => {
173187
const cell = this._grid.getCell(x, y)
174188

@@ -190,14 +204,18 @@ export class NeovimScreen implements IScreen {
190204
this._currentHighlight.foregroundColor || this._foregroundColor
191205
let backgroundColor =
192206
this._currentHighlight.backgroundColor || this._backgroundColor
207+
const specialColor = this._currentHighlight.specialColor || this._specialColor
193208

209+
// `:help ui-event-highlight_set` specifies that the background and foreground colours
210+
// are swapped if reversed is set. The special colour is not mentioned, which is why it
211+
// is omitted here.
194212
if (this._currentHighlight.reverse) {
195213
const temp = foregroundColor
196214
foregroundColor = backgroundColor
197215
backgroundColor = temp
198216
}
199217

200-
const { underline, bold, italic } = this._currentHighlight
218+
const { underline, undercurl, bold, italic } = this._currentHighlight
201219

202220
const characters = action.characters
203221
const row = this._cursorRow
@@ -211,22 +229,26 @@ export class NeovimScreen implements IScreen {
211229
this._setCell(col + i, row, {
212230
foregroundColor,
213231
backgroundColor,
232+
specialColor,
214233
character,
215234
characterWidth,
216235
italic,
217236
bold,
218237
underline,
238+
undercurl,
219239
})
220240

221241
for (let c = 1; c < characterWidth; c++) {
222242
this._setCell(col + i + c, row, {
223243
foregroundColor,
224244
backgroundColor,
245+
specialColor,
225246
character: "",
226247
characterWidth: 0,
227248
italic,
228249
bold,
229250
underline,
251+
undercurl,
230252
})
231253
}
232254

@@ -241,17 +263,20 @@ export class NeovimScreen implements IScreen {
241263
this._currentHighlight.foregroundColor || this._foregroundColor
242264
const backgroundColor =
243265
this._currentHighlight.backgroundColor || this._backgroundColor
266+
const specialColor = this._currentHighlight.specialColor || this._specialColor
244267

245268
const row = this._cursorRow
246269
for (let i = this._cursorColumn; i < this.width; i++) {
247270
this._setCell(i, row, {
248271
foregroundColor,
249272
backgroundColor,
273+
specialColor,
250274
character: "",
251275
characterWidth: 1,
252276
bold: this._currentHighlight.bold,
253277
italic: this._currentHighlight.italic,
254278
underline: this._currentHighlight.underline,
279+
undercurl: this._currentHighlight.undercurl,
255280
})
256281
}
257282
break
@@ -289,6 +314,7 @@ export class NeovimScreen implements IScreen {
289314
const { isBoldAvailable, isItalicAvailable } = this._currentHighlight
290315
this._currentHighlight.foregroundColor = action.foregroundColor
291316
this._currentHighlight.backgroundColor = action.backgroundColor
317+
this._currentHighlight.specialColor = action.specialColor
292318
this._currentHighlight.reverse = !!action.reverse
293319
this._currentHighlight.bold = isBoldAvailable ? action.bold : false
294320
this._currentHighlight.italic = isItalicAvailable ? action.italic : false

browser/src/neovim/actions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface ISetHighlightAction extends IAction {
8585

8686
foregroundColor?: string
8787
backgroundColor?: string
88+
specialColor?: string
8889
}
8990

9091
export function scroll(scrollValue: number): IScrollAction {
@@ -117,6 +118,7 @@ export function setHighlight(
117118
undercurl: boolean,
118119
foregroundColor?: number,
119120
backgroundColor?: number,
121+
specialColor?: number,
120122
): ISetHighlightAction {
121123
const action: ISetHighlightAction = {
122124
type: SET_HIGHLIGHT,
@@ -127,6 +129,7 @@ export function setHighlight(
127129
undercurl,
128130
foregroundColor: undefined,
129131
backgroundColor: undefined,
132+
specialColor: undefined,
130133
}
131134

132135
if (foregroundColor && foregroundColor !== -1) {
@@ -137,6 +140,10 @@ export function setHighlight(
137140
action.backgroundColor = colorToString(backgroundColor, "#000000")
138141
}
139142

143+
if (specialColor && specialColor !== -1) {
144+
action.specialColor = colorToString(specialColor, "#000000")
145+
}
146+
140147
return action
141148
}
142149

0 commit comments

Comments
 (0)