Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/src/neovim/NeovimInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ export class NeovimInstance extends EventEmitter implements INeovimInstance {
!!highlightInfo.undercurl,
highlightInfo.foreground,
highlightInfo.background,
highlightInfo.special,
),
)
break
Expand Down
28 changes: 27 additions & 1 deletion browser/src/neovim/Screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface IHighlight {

foregroundColor?: string
backgroundColor?: string
specialColor?: string

isItalicAvailable?: boolean
isBoldAvailable?: boolean
}
Expand Down Expand Up @@ -64,9 +66,12 @@ export interface ICell {

foregroundColor?: string
backgroundColor?: string
specialColor?: string

italic?: boolean
bold?: boolean
underline?: boolean
undercurl?: boolean
}

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

export class NeovimScreen implements IScreen {
private _backgroundColor: string = "#000000"
private _specialColor: string = "#000000"
private _currentHighlight: IHighlight = {}
private _cursorColumn: number = 0
private _cursorRow: number = 0
Expand Down Expand Up @@ -161,6 +167,10 @@ export class NeovimScreen implements IScreen {
return this._foregroundColor
}

public get specialColor(): string {
return this._specialColor
}

public get currentForegroundColor(): string {
return this._currentHighlight.foregroundColor || this._foregroundColor
}
Expand All @@ -169,6 +179,10 @@ export class NeovimScreen implements IScreen {
return this._currentHighlight.backgroundColor || this._backgroundColor
}

public get currentSpecialColor(): string {
return this._currentHighlight.specialColor || this._specialColor
}

public getCell = (x: number, y: number) => {
const cell = this._grid.getCell(x, y)

Expand All @@ -190,14 +204,18 @@ export class NeovimScreen implements IScreen {
this._currentHighlight.foregroundColor || this._foregroundColor
let backgroundColor =
this._currentHighlight.backgroundColor || this._backgroundColor
const specialColor = this._currentHighlight.specialColor || this._specialColor

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

const { underline, bold, italic } = this._currentHighlight
const { underline, undercurl, bold, italic } = this._currentHighlight

const characters = action.characters
const row = this._cursorRow
Expand All @@ -211,22 +229,26 @@ export class NeovimScreen implements IScreen {
this._setCell(col + i, row, {
foregroundColor,
backgroundColor,
specialColor,
character,
characterWidth,
italic,
bold,
underline,
undercurl,
})

for (let c = 1; c < characterWidth; c++) {
this._setCell(col + i + c, row, {
foregroundColor,
backgroundColor,
specialColor,
character: "",
characterWidth: 0,
italic,
bold,
underline,
undercurl,
})
}

Expand All @@ -241,17 +263,20 @@ export class NeovimScreen implements IScreen {
this._currentHighlight.foregroundColor || this._foregroundColor
const backgroundColor =
this._currentHighlight.backgroundColor || this._backgroundColor
const specialColor = this._currentHighlight.specialColor || this._specialColor

const row = this._cursorRow
for (let i = this._cursorColumn; i < this.width; i++) {
this._setCell(i, row, {
foregroundColor,
backgroundColor,
specialColor,
character: "",
characterWidth: 1,
bold: this._currentHighlight.bold,
italic: this._currentHighlight.italic,
underline: this._currentHighlight.underline,
undercurl: this._currentHighlight.undercurl,
})
}
break
Expand Down Expand Up @@ -289,6 +314,7 @@ export class NeovimScreen implements IScreen {
const { isBoldAvailable, isItalicAvailable } = this._currentHighlight
this._currentHighlight.foregroundColor = action.foregroundColor
this._currentHighlight.backgroundColor = action.backgroundColor
this._currentHighlight.specialColor = action.specialColor
this._currentHighlight.reverse = !!action.reverse
this._currentHighlight.bold = isBoldAvailable ? action.bold : false
this._currentHighlight.italic = isItalicAvailable ? action.italic : false
Expand Down
7 changes: 7 additions & 0 deletions browser/src/neovim/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface ISetHighlightAction extends IAction {

foregroundColor?: string
backgroundColor?: string
specialColor?: string
}

export function scroll(scrollValue: number): IScrollAction {
Expand Down Expand Up @@ -117,6 +118,7 @@ export function setHighlight(
undercurl: boolean,
foregroundColor?: number,
backgroundColor?: number,
specialColor?: number,
): ISetHighlightAction {
const action: ISetHighlightAction = {
type: SET_HIGHLIGHT,
Expand All @@ -127,6 +129,7 @@ export function setHighlight(
undercurl,
foregroundColor: undefined,
backgroundColor: undefined,
specialColor: undefined,
}

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

if (specialColor && specialColor !== -1) {
action.specialColor = colorToString(specialColor, "#000000")
}

return action
}

Expand Down