Open kristofferdamborg opened 1 year ago
There is no blur
, but I think focus
can be used as is.
There is no
blur
, but I thinkfocus
can be used as is.
@logue It doesn't seem to work unfortunately. Here's a Stackblitz replication: https://stackblitz.com/edit/vue-ump37q?file=src%2Fcomponents%2FEditor.vue
@logue It unfortunately doesn't seem like https://github.com/logue/vue-codemirror6/commit/f5d4fd9ba39761779e54da0f53727e31616e8446 fixed it. There's still no focus event triggered :(
Here's an updated Stackblitz (with version 1.1.26): https://vue-ump37q.stackblitz.io
@logue
A possible solution is to add a focusChangeEffect as an extension. Tested to be working locally, see example below.
function focusEffectHandler(state: EditorState, focusing: boolean): StateEffect<any> | null {
if (focusing) {
emit('focus');
} else {
emit('blur');
}
return null;
}
const extensions = [
EditorView.focusChangeEffect.of(focusEffectHandler),
// ...other extensions
];
In 1.1.27, focus
was solved by hooking ViewUpdate
. As a side effect, character count processing and error counting processing are faster.
However, regarding blur
, the official answer is as follows, but it didn't work when I implemented it, so I decided to postpone it.
https://discuss.codemirror.net/t/code-mirror-6-has-focus-what-about-blur/4071
I skipped the implementation of blur
because it seems to be hitting the DOM directly instead of CodeMirror's function.
So, for blur
, I'm thinking of releasing an API that can hit the dom (contentDOM
).
I have previously used the vue wrapper for CodeMirror 5 (https://github.com/RennZhang/codemirror-editor-vue3) which supported binding the
focus
andblur
event directly on the component. Is it possible to do this as well withvue-codemirror6
?Example: