Skip to content

Commit

Permalink
feat(markdown): use CocFloatActive for active highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Oct 7, 2022
1 parent d0a5ed3 commit 54d8212
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
5 changes: 4 additions & 1 deletion doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ window with current variable name.
------------------------------------------------------------------------------
SIGNATURE HELP *coc-signature*

Signature help of function is automatically triggered by default(when user
Signature help of function is automatically triggered by default (when user
type trigger characters defined by the provider), which will use float
window/popup to show the signature documentations by default.

Expand All @@ -781,6 +781,8 @@ if signature help provider exists.

Use |coc-config-signature| to change default signature help behavior.

|CocFloatActive| is used for highlight activated parameter part.

------------------------------------------------------------------------------
INLAY HINT *coc-inlayHint*

Expand Down Expand Up @@ -3063,6 +3065,7 @@ Default links to |NormalFloat| on neovim and |Pmenu| on vim.
*CocFloatThumb* thumb highlight of scrollbar.
*CocFloatSbar* Scrollbar highlight of floating window/popups.
*CocFloatDividingLine* for dividing lines, links to |NonText| by default.
*CocFloatActive* for activated text, links to |CocSearch| by default.
*CocErrorFloat* for error text in floating windows/popups.
*CocHintFloat* for hint text in floating windows/popups.

Expand Down
1 change: 1 addition & 0 deletions plugin/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ function! s:Highlight() abort
hi default link CocFloatThumb PmenuThumb
hi default link CocFloatSbar PmenuSbar
endif
hi default link CocFloatActive CocSearch
hi default link CocFadeOut Conceal
hi default link CocMarkdownCode markdownCode
hi default link CocMarkdownHeader markdownH1
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/handler/signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('signatureHelp', () => {
expect(win).toBeDefined()
let highlights = await win.getVar('highlights')
expect(highlights).toBeDefined()
expect(highlights[0].hlGroup).toBe('CocUnderline')
expect(highlights[0].hlGroup).toBe('CocFloatActive')
})

it('should trigger by space', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/markdown/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('getHighlightItems', () => {
colStart: 10,
colEnd: 15,
lnum: 0,
hlGroup: 'CocUnderline'
hlGroup: 'CocFloatActive'
}])
})

Expand All @@ -18,22 +18,22 @@ describe('getHighlightItems', () => {
colStart: 5,
colEnd: 9,
lnum: 0,
hlGroup: 'CocUnderline'
hlGroup: 'CocFloatActive'
}])
})

it('should get highlights across line', async () => {
let res = getHighlightItems('this line\nhas highlights', 0, [5, 15])
expect(res).toEqual([{
colStart: 5, colEnd: 9, lnum: 0, hlGroup: 'CocUnderline'
colStart: 5, colEnd: 9, lnum: 0, hlGroup: 'CocFloatActive'
}, {
colStart: 0, colEnd: 5, lnum: 1, hlGroup: 'CocUnderline'
colStart: 0, colEnd: 5, lnum: 1, hlGroup: 'CocFloatActive'
}])
res = getHighlightItems('a\nb\nc\nd', 0, [2, 5])
expect(res).toEqual([
{ colStart: 0, colEnd: 1, lnum: 1, hlGroup: 'CocUnderline' },
{ colStart: 0, colEnd: 1, lnum: 2, hlGroup: 'CocUnderline' },
{ colStart: 0, colEnd: 0, lnum: 3, hlGroup: 'CocUnderline' }
{ colStart: 0, colEnd: 1, lnum: 1, hlGroup: 'CocFloatActive' },
{ colStart: 0, colEnd: 1, lnum: 2, hlGroup: 'CocFloatActive' },
{ colStart: 0, colEnd: 0, lnum: 3, hlGroup: 'CocFloatActive' }
])
})
})
Expand Down Expand Up @@ -264,6 +264,6 @@ describe('parseDocuments', () => {
active: [15, 20]
}]
let res = parseDocuments(docs as any)
expect(res.highlights[0]).toEqual({ colStart: 5, colEnd: 8, lnum: 0, hlGroup: 'CocUnderline' })
expect(res.highlights[0]).toEqual({ colStart: 5, colEnd: 8, lnum: 0, hlGroup: 'CocFloatActive' })
})
})
12 changes: 7 additions & 5 deletions src/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { HighlightItem, Documentation } from '../types'
export const diagnosticFiletypes = ['Error', 'Warning', 'Info', 'Hint']
const logger = require('../util/logger')('markdown-index')

const ACTIVE_HL_GROUP = 'CocFloatActive'

export interface MarkdownParseOptions {
excludeImages?: boolean
}
Expand Down Expand Up @@ -82,7 +84,7 @@ export function parseDocuments(docs: Documentation[], opts: MarkdownParseOptions
}

/**
* Get 'CocUnderline' highlights from offset range
* Get 'CocSearch' highlights from offset range
*/
export function getHighlightItems(content: string, currline: number, active: [number, number]): HighlightItem[] {
let res: HighlightItem[] = []
Expand All @@ -99,22 +101,22 @@ export function getHighlightItems(content: string, currline: number, active: [nu
if (used + line.length > end) {
let colEnd = byteLength(line.slice(0, end - used))
inRange = false
res.push({ colStart, colEnd, lnum: i + currline, hlGroup: 'CocUnderline' })
res.push({ colStart, colEnd, lnum: i + currline, hlGroup: ACTIVE_HL_GROUP })
break
} else {
let colEnd = byteLength(line)
res.push({ colStart, colEnd, lnum: i + currline, hlGroup: 'CocUnderline' })
res.push({ colStart, colEnd, lnum: i + currline, hlGroup: ACTIVE_HL_GROUP })
}
}
} else {
if (used + line.length > end) {
let colEnd = byteLength(line.slice(0, end - used))
res.push({ colStart: 0, colEnd, lnum: i + currline, hlGroup: 'CocUnderline' })
res.push({ colStart: 0, colEnd, lnum: i + currline, hlGroup: ACTIVE_HL_GROUP })
inRange = false
break
} else {
let colEnd = byteLength(line)
res.push({ colStart: 0, colEnd, lnum: i + currline, hlGroup: 'CocUnderline' })
res.push({ colStart: 0, colEnd, lnum: i + currline, hlGroup: ACTIVE_HL_GROUP })
}
}
used = used + line.length + 1
Expand Down

0 comments on commit 54d8212

Please sign in to comment.