react-mde
Version:
React Markdown Editor
25 lines (24 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.italicCommand = void 0;
var MarkdownUtil_1 = require("../../util/MarkdownUtil");
exports.italicCommand = {
buttonProps: { "aria-label": "Add italic 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 italic mark up
var state2 = textApi.replaceSelection("*" + state1.selectedText + "*");
// Adjust the selection to not contain the *
textApi.setSelectionRange({
start: state2.selection.end - 1 - state1.selectedText.length,
end: state2.selection.end - 1
});
},
handleKeyCommand: function (e) { return (e.ctrlKey || e.metaKey) && e.key == "i"; }
};