fix: markdown editor URL autocompletion (#2452)
Fix for #2062. Using token.string only captured the character at the cursor. Now using the cursor location to determine suitable search text. Also corrected syntax issue where suggestion removed opening link parenthesis.
This commit is contained in:
parent
352d7c2bf1
commit
5a9df24f04
@ -626,6 +626,8 @@ export default {
|
|||||||
cm.showHint({
|
cm.showHint({
|
||||||
hint: async (cm, options) => {
|
hint: async (cm, options) => {
|
||||||
const cur = cm.getCursor()
|
const cur = cm.getCursor()
|
||||||
|
const curLine = cm.getLine(cur.line).substring(0, cur.ch)
|
||||||
|
const queryString = curLine.substring(curLine.lastIndexOf('[')+1,curLine.length-2)
|
||||||
const token = cm.getTokenAt(cur)
|
const token = cm.getTokenAt(cur)
|
||||||
try {
|
try {
|
||||||
const respRaw = await this.$apollo.query({
|
const respRaw = await this.$apollo.query({
|
||||||
@ -644,7 +646,7 @@ export default {
|
|||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
variables: {
|
variables: {
|
||||||
query: token.string,
|
query: queryString,
|
||||||
locale: this.locale
|
locale: this.locale
|
||||||
},
|
},
|
||||||
fetchPolicy: 'cache-first'
|
fetchPolicy: 'cache-first'
|
||||||
@ -653,7 +655,7 @@ export default {
|
|||||||
if (resp && resp.totalHits > 0) {
|
if (resp && resp.totalHits > 0) {
|
||||||
return {
|
return {
|
||||||
list: resp.results.map(r => ({
|
list: resp.results.map(r => ({
|
||||||
text: (siteLangs.length > 0 ? `/${r.locale}/${r.path}` : `/${r.path}`) + ')',
|
text: '(' + (siteLangs.length > 0 ? `/${r.locale}/${r.path}` : `/${r.path}`) + ')',
|
||||||
displayText: siteLangs.length > 0 ? `/${r.locale}/${r.path} - ${r.title}` : `/${r.path} - ${r.title}`
|
displayText: siteLangs.length > 0 ? `/${r.locale}/${r.path} - ${r.title}` : `/${r.path} - ${r.title}`
|
||||||
})),
|
})),
|
||||||
from: CodeMirror.Pos(cur.line, token.start),
|
from: CodeMirror.Pos(cur.line, token.start),
|
||||||
|
Loading…
Reference in New Issue
Block a user