Skip to content

Commit

Permalink
fix shortcuts, link title #1168 #1190
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Nov 24, 2023
1 parent 924a2c7 commit f375d70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
7 changes: 3 additions & 4 deletions src/assets/icons/_default.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Editor.prototype = {
* @param {Array.<Element>|null} targets Plugin target button (This is not necessary if you have a button list when creating the editor)
* @param {object|null} pluginOptions Plugin's options
*/
registerPlugin(pluginName, targets, pluginOptions) {
registerPlugin(pluginName, targets, pluginOptions, shortcut) {
let plugin = this.plugins[pluginName];
if (!plugin) {
throw Error(`[SUNEDITOR.registerPlugin.fail] The called plugin does not exist or is in an invalid format. (pluginName: "${pluginName}")`);
Expand All @@ -284,7 +284,7 @@ Editor.prototype = {

if (targets) {
for (let i = 0, len = targets.length; i < len; i++) {
UpdateButton(targets[i], plugin, this.icons, this.lang);
UpdateButton(targets[i], plugin, this.icons, this.lang, shortcut);
}

if (!this.activeCommands.includes(pluginName) && typeof this.plugins[pluginName].active === 'function') {
Expand Down Expand Up @@ -1253,11 +1253,12 @@ Editor.prototype = {

const plugins = this.plugins;
const isArray = Array.isArray;
const shortcuts = this.options.get('shortcuts');
let filePluginRegExp = [];
let plugin;
for (let key in plugins) {
this.registerPlugin(key, this._pluginCallButtons[key], options[key]);
this.registerPlugin(key, this._pluginCallButtons_sub[key], options[key]);
this.registerPlugin(key, this._pluginCallButtons[key], options[key], shortcuts[key]);
this.registerPlugin(key, this._pluginCallButtons_sub[key], options[key], shortcuts[key]);
plugin = this.plugins[key];

// Filemanager
Expand Down
31 changes: 23 additions & 8 deletions src/core/section/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,16 @@ export function CreateShortcuts(command, button, values, keyMap, rc, reverseKeys
}

if (!(t = values[i + 1])) continue;
if (tooptip)
tooptip.appendChild(
domUtils.createElement('SPAN', { class: 'se-shortcut' }, env.cmdIcon + (s ? env.shiftIcon : '') + '+<span class="se-shortcut-key">' + t + '</span>')
);
if (tooptip) _addTooltip(tooptip, s, t);
}
}

function _addTooltip(tooptipBtn, shift, shortcut) {
tooptipBtn.appendChild(
domUtils.createElement('SPAN', { class: 'se-shortcut' }, env.cmdIcon + (shift ? env.shiftIcon : '') + '+<span class="se-shortcut-key">' + shortcut + '</span>')
);
}

/**
* @description Returns a new object with merge "a" and "b"
* @param {Object} obj object
Expand Down Expand Up @@ -489,6 +492,7 @@ export function InitOptions(options, editorTargets) {
? {}
: [
{
// default command
selectAll: ['65', 'A'],
bold: ['66', 'B'],
strike: ['s83', 'S'],
Expand All @@ -500,7 +504,9 @@ export function InitOptions(options, editorTargets) {
outdent: ['219', '['],
sup: ['187', '='],
sub: ['s187', '='],
save: ['83', 'S']
save: ['83', 'S'],
// plugins
link: ['75', 'K']
},
options.shortcuts || {}
].reduce(function (_default, _new) {
Expand Down Expand Up @@ -877,8 +883,8 @@ function _defaultButtons(options, icons, lang) {
dir_ltr: ['', lang.dir_ltr, 'dir_ltr', '', icons.dir_ltr],
dir_rtl: ['', lang.dir_rtl, 'dir_rtl', '', icons.dir_rtl],
save: ['se-resizing-enabled', lang.save, 'save', '', icons.save],
newDocument: ['se-resizing-enabled', lang.newDocument, 'newDocument', '', icons.newDocument],
selectAll: ['se-resizing-enabled', lang.selectAll, 'selectAll', '', icons.selectAll],
newDocument: ['se-resizing-enabled', lang.newDocument, 'newDocument', '', icons.new_document],
selectAll: ['se-resizing-enabled', lang.selectAll, 'selectAll', '', icons.select_all]
};
}

Expand Down Expand Up @@ -940,7 +946,7 @@ function _createButton(className, title, dataCommand, dataType, innerHTML, _disa
};
}

export function UpdateButton(element, plugin, icons, lang) {
export function UpdateButton(element, plugin, icons, lang, shortcut) {
if (!element) return;
element.innerHTML =
(icons[plugin.icon] || plugin.icon || '<span class="se-icon-text">!</span>') +
Expand All @@ -950,6 +956,15 @@ export function UpdateButton(element, plugin, icons, lang) {
element.setAttribute('aria-label', plugin.title);
if (plugin.type) element.setAttribute('data-type', plugin.type);
if (plugin.className) element.className += ' ' + plugin.className;

const tooptip = element.querySelector('.se-tooltip-text');
if (!shortcut || !tooptip) return;

for (let i = 0, s, t; i < shortcut.length; i += 2) {
s = /^s/i.test(shortcut[i]);
if (!(t = shortcut[i + 1])) continue;
_addTooltip(tooptip, s, t);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ModalAnchorEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function CreatetModalForm(editor, params, relList) {
</div>
<label ${textDisplayShow}>${lang.link_modal_text}</label>
<input class="se-input-form _se_display_text" type="text" ${textDisplayShow} />
<label ${titleShow}>${lang.link_modal_title}</label>
<label ${titleShow}>${lang.title}</label>
<input class="se-input-form _se_title" type="text" ${titleShow} />
</div>
<div class="se-modal-form-footer">
Expand Down

0 comments on commit f375d70

Please sign in to comment.