Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"url": "https://github.com/ether/ep_headings2/issues"
},
"dependencies": {
"ep_plugin_helpers": "^0.5.2"
"ep_plugin_helpers": "^0.6.0"
},
"devDependencies": {
"eslint": "^8.57.1",
Expand Down
23 changes: 10 additions & 13 deletions static/js/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const {lineAttribute} = require('ep_plugin_helpers/attributes');
const {toolbarSelect} = require('ep_plugin_helpers/toolbar-select');

const cssFiles = ['ep_headings2/static/css/editor.css'];
const tags = ['h1', 'h2', 'h3', 'h4', 'code'];
Expand All @@ -15,20 +16,16 @@ exports.aceRegisterBlockElements = headings.aceRegisterBlockElements;
exports.aceAttribsToClasses = headings.aceAttribsToClasses;
exports.aceDomLineProcessLineAttributes = headings.aceDomLineProcessLineAttributes;

// Bind the event handler to the toolbar buttons
// Bind the event handler to the toolbar buttons. The helper guarantees
// focus is returned to the editor after every change — including
// invalid picks — preserving the behavior of the original handler that
// fixed #130.
exports.postAceInit = (hookName, context) => {
const hs = $('#heading-selection');
hs.on('change', function () {
const value = $(this).val();
const intValue = parseInt(value, 10);
if (!isNaN(intValue)) {
context.ace.callWithAce((ace) => {
ace.ace_doInsertHeading(intValue);
}, 'insertheading', true);
hs.val('dummy');
}
// Return focus to the editor after heading selection (fixes #130)
context.ace.focus();
toolbarSelect({
selector: '#heading-selection',
context,
invoke: (ace, value) => ace.ace_doInsertHeading(value),
op: 'insertheading',
});
};

Expand Down
Loading