react-mde
Version:
React Markdown Editor
25 lines (24 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.boldCommand = void 0;
var MarkdownUtil_1 = require("../../util/MarkdownUtil");
exports.boldCommand = {
buttonProps: { "aria-label": "Add bold text" },
execute: function (_a) {
var initialState = _a.initialState, textApi = _a.textApi;
// Adjust the selection to encompass the whole word if the caret is inside one
var newSelectionRange = MarkdownUtil_1.selectWord({
text: initialState.text,
selection: initialState.selection
});
var state1 = textApi.setSelectionRange(newSelectionRange);
// Replaces the current selection with the bold mark up
var state2 = textApi.replaceSelection("**" + state1.selectedText + "**");
// Adjust the selection to not contain the **
textApi.setSelectionRange({
start: state2.selection.end - 2 - state1.selectedText.length,
end: state2.selection.end - 2
});
},
handleKeyCommand: function (e) { return (e.ctrlKey || e.metaKey) && e.key == "b"; }
};