mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
refactor: improve trigger characters for path completion and handle wiki links in emoji completion
This commit is contained in:
@@ -62,7 +62,7 @@ interface CompletionContext {
|
||||
}
|
||||
|
||||
class CompletionProvider implements Monaco.languages.CompletionItemProvider {
|
||||
triggerCharacters = ['/', '#', '[']
|
||||
triggerCharacters = ['/', ':', '#', '[']
|
||||
|
||||
private readonly monaco: typeof Monaco
|
||||
private readonly ctx: Ctx
|
||||
@@ -263,17 +263,24 @@ class CompletionProvider implements Monaco.languages.CompletionItemProvider {
|
||||
}
|
||||
|
||||
private async * providePathSuggestions (position: Monaco.Position, context: CompletionContext): AsyncIterable<Monaco.languages.CompletionItem> {
|
||||
const valueBeforeLastSlash = context.linkPrefix.substring(0, context.linkPrefix.lastIndexOf('/') + 1) // keep the last slash
|
||||
let idx = context.linkPrefix.lastIndexOf('/')
|
||||
|
||||
if (context.kind === CompletionContextKind.WikiLink) {
|
||||
idx = Math.max(context.linkPrefix.lastIndexOf(':'), idx)
|
||||
}
|
||||
|
||||
const valueBeforeLastSlash = context.linkPrefix.substring(0, idx + 1) // keep the last slash
|
||||
|
||||
const currentFile = this.ctx.store.state.currentFile
|
||||
if (!currentFile) {
|
||||
return
|
||||
}
|
||||
|
||||
const parentDir = this.ctx.utils.path.resolve(
|
||||
this.ctx.utils.path.dirname(currentFile.path),
|
||||
valueBeforeLastSlash || '.'
|
||||
)
|
||||
const basePath = this.ctx.utils.path.dirname(currentFile.path)
|
||||
|
||||
const parentDir = context.kind === CompletionContextKind.WikiLink
|
||||
? this.ctx.utils.path.resolve(basePath, valueBeforeLastSlash.replace(/:/g, '/') || '.')
|
||||
: this.ctx.utils.path.resolve(basePath, valueBeforeLastSlash || '.')
|
||||
|
||||
const pathSegmentStart = position.delta(0, valueBeforeLastSlash.length - context.linkPrefix.length)
|
||||
const insertRange = new this.monaco.Range(
|
||||
|
||||
@@ -25,6 +25,11 @@ class EmojiCompletionProvider implements Monaco.languages.CompletionItemProvider
|
||||
const cursor = position.column - 1
|
||||
const linePrefixText = line.slice(0, cursor)
|
||||
|
||||
// Check if the cursor is in a wiki link
|
||||
if (linePrefixText.lastIndexOf('[[') > linePrefixText.lastIndexOf(']]')) {
|
||||
return { suggestions: [] }
|
||||
}
|
||||
|
||||
const match = linePrefixText.match(/:[a-zA-Z0-9]*$/)
|
||||
if (!match || linePrefixText.charAt(linePrefixText.length - match[0].length - 1) === ':') {
|
||||
return { suggestions: [] }
|
||||
|
||||
Reference in New Issue
Block a user