-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support CodeMirror 6 #10
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
da36699
Update plugin API
personalizedrefrigerator 8d3cf19
Support CodeMirror 6
personalizedrefrigerator db29a8e
Don't use langaugeData-based completions
personalizedrefrigerator 3286b5d
Remove added sans-serif font from show-hint.css
personalizedrefrigerator 5e764d4
Revert changes to package-lock.json
personalizedrefrigerator df1df85
Revert unnecessary changes to api/*
personalizedrefrigerator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extraScripts": [ | ||
"InlineTagsPlugin.ts" | ||
"contentScript/index.ts" | ||
] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { PluginContext } from './types'; | ||
|
||
|
||
const codeMirror5Plugin = (context: PluginContext, CodeMirror: any) => { | ||
const buildHints = async (prefix: string) =>{ | ||
const {tags, keepText } = await context.postMessage({ | ||
command: 'getTags', | ||
}); | ||
let hints = []; | ||
for (let i = 0; i < tags.length; i++) { | ||
const tag = tags[i]; | ||
if (prefix === '#' || tag.title.startsWith(prefix)) { | ||
hints.push({ | ||
text: '#' + tag.title, | ||
displayText: tag.title, | ||
hint: async (cm, data, completion) => { | ||
context.postMessage({ | ||
command: 'setTag', | ||
tag: tag, | ||
}); | ||
if (!!keepText) { | ||
cm.replaceRange(tag.title, completion.from || data.from, cm.getCursor(), "complete"); | ||
} else { | ||
const from = completion.from || data.from; | ||
from.ch -= 1; | ||
cm.replaceRange('', from, cm.getCursor(), "complete"); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
if (prefix !== '#') { | ||
const tagExists = tags.findIndex(t => t.title === prefix) > 0; | ||
if (!tagExists) { | ||
hints.push({ | ||
text: `Create new tag: ${prefix}`, | ||
hint: (cm, data, completion) => { | ||
context.postMessage({ | ||
command: 'newTag', | ||
name: prefix, | ||
}); | ||
if (!keepText) { | ||
const from = completion.from || data.from; | ||
from.ch -= 1; | ||
cm.replaceRange('', from, cm.getCursor(), "complete"); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
return hints; | ||
} | ||
CodeMirror.defineOption('inlineTags', false, function(cm, value, prev) { | ||
if (!value) return; | ||
cm.on('inputRead', async function (cm1, change) { | ||
if (!cm1.state.completionActive && change.text[0] === '#') { | ||
const content = await cm1.getValue().split('\n'); | ||
let count=0; | ||
for(let i=0;i<content.length;i++){ | ||
if(content[i].startsWith('```')){ | ||
count++; | ||
if(i==change.from.line){ | ||
return; | ||
} | ||
} | ||
if(i==change.from.line && count%2){ | ||
return; | ||
} | ||
} | ||
const start = {line: change.from.line, ch: change.from.ch + 1}; | ||
const hint = function(cm, callback) { | ||
const cursor = cm.getCursor(); | ||
const token = cm.getRange(start, cursor); | ||
|
||
buildHints(token).then(hints => { | ||
callback({ | ||
list: hints, | ||
from: {line: change.from.line, ch: change.from.ch + 1}, | ||
to: {line: change.to.line, ch: change.to.ch + 1}, | ||
}); | ||
}); | ||
}; | ||
|
||
setTimeout(function () { | ||
CodeMirror.showHint(cm, hint, { | ||
completeSingle: false, | ||
closeOnUnfocus: true, | ||
async: true, | ||
}); | ||
}, 10); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export default codeMirror5Plugin; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
andnpm
weren't in the original template and seem to be unused. As such, I have removed them here.Please let me know if they should be added back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see in git log they were there from the very beginning, not sure why.