@atlaskit/editor-plugin-code-block-advanced
Version:
CodeBlockAdvanced plugin for @atlaskit/editor-core
26 lines (25 loc) • 965 B
JavaScript
import { EditorSelection } from '@codemirror/state';
import { EditorView as CodeMirror } from '@codemirror/view';
/**
* To have consistent behaviour with previous code block when a triple click occurs in the editor
* we should select the entire code block rather than the line.
*
* @returns CodeMirror extension
*/
export var tripleClickSelectAllExtension = function tripleClickSelectAllExtension() {
return CodeMirror.mouseSelectionStyle.of(function (view, event) {
// Check for a triple-click and avoid non-main "button" events
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
if (event.detail !== 3 || event.button !== 0) {
return null;
}
return {
// Select the entire document
get: function get() {
return EditorSelection.single(0, view.state.doc.length);
},
update: function update() {}
};
});
};