diff --git a/src/mjs/constant.js b/src/mjs/constant.js index 29c5fa57..e1afc08b 100644 --- a/src/mjs/constant.js +++ b/src/mjs/constant.js @@ -4,6 +4,9 @@ export const CONTENT_GET = 'getContent'; export const CONTEXT_MENU = 'contextMenu'; +export const EDIT_HTML = 'editHtml'; +export const EDIT_MD = 'editMarkdown'; +export const EDIT_TXT = 'editPlainText'; export const EDITOR_CONFIG_GET = 'getEditorConfig'; export const EDITOR_CONFIG_RES = 'resEditorConfig'; export const EDITOR_CONFIG_TS = 'editorConfigTimestamp'; @@ -57,7 +60,7 @@ export const MODE_EDIT = 'modeEditText'; export const MODE_EDIT_EXT = 'modeEditTextFileExtension'; export const MODE_EDIT_HTML = 'modeEditTextHtml'; export const MODE_EDIT_MD = 'modeEditTextMarkdown'; -export const MODE_EDIT_TXT = 'modeEditTextPlaintext'; +export const MODE_EDIT_TXT = 'modeEditTextPlainText'; export const MODE_MATHML = 'modeViewMathML'; export const MODE_SELECTION = 'modeViewSelection'; export const MODE_SOURCE = 'modeViewSource'; diff --git a/src/mjs/main.js b/src/mjs/main.js index 9af41962..e63cf5f5 100644 --- a/src/mjs/main.js +++ b/src/mjs/main.js @@ -14,19 +14,19 @@ import { } from './common.js'; import { setIconBadge } from './icon.js'; import { - CONTENT_GET, CONTEXT_MENU, EDITOR_CONFIG_GET, EDITOR_CONFIG_RES, - EDITOR_CONFIG_TS, EDITOR_EXEC, EDITOR_FILE_NAME, EDITOR_LABEL, EXT_NAME, - FILE_EXT_SELECT, FILE_EXT_SELECT_HTML, FILE_EXT_SELECT_MD, - FILE_EXT_SELECT_TXT, HOST, HOST_COMPAT, HOST_CONNECTION, HOST_ERR_NOTIFY, - HOST_STATUS, HOST_STATUS_GET, HOST_VERSION, HOST_VERSION_CHECK, - HOST_VERSION_LATEST, HOST_VERSION_MIN, ICON, INFO_COLOR, INFO_TEXT, - IS_CONNECTABLE, IS_EXECUTABLE, IS_MAC, LOCAL_FILE_VIEW, MENU_ENABLED, - MODE_EDIT, MODE_EDIT_EXT, MODE_EDIT_HTML, MODE_EDIT_MD, MODE_EDIT_TXT, - MODE_MATHML, MODE_SELECTION, MODE_SOURCE, MODE_SVG, ONLY_EDITABLE, - OPTIONS_OPEN, PATH_OPTIONS_PAGE, PROCESS_CHILD, SYNC_AUTO, SYNC_AUTO_URL, - TMP_FILES_PB, TMP_FILES_PB_REMOVE, TMP_FILE_CREATE, TMP_FILE_DATA_PORT, - TMP_FILE_DATA_REMOVE, TMP_FILE_GET, TMP_FILE_REQ, TMP_FILE_RES, VARS_SET, - WARN_COLOR, WARN_TEXT + CONTENT_GET, CONTEXT_MENU, EDIT_HTML, EDIT_MD, EDIT_TXT, EDITOR_CONFIG_GET, + EDITOR_CONFIG_RES, EDITOR_CONFIG_TS, EDITOR_EXEC, EDITOR_FILE_NAME, + EDITOR_LABEL, EXT_NAME, FILE_EXT_SELECT, FILE_EXT_SELECT_HTML, + FILE_EXT_SELECT_MD, FILE_EXT_SELECT_TXT, HOST, HOST_COMPAT, HOST_CONNECTION, + HOST_ERR_NOTIFY, HOST_STATUS, HOST_STATUS_GET, HOST_VERSION, + HOST_VERSION_CHECK, HOST_VERSION_LATEST, HOST_VERSION_MIN, ICON, INFO_COLOR, + INFO_TEXT, IS_CONNECTABLE, IS_EXECUTABLE, IS_MAC, LOCAL_FILE_VIEW, + MENU_ENABLED, MODE_EDIT, MODE_EDIT_EXT, MODE_EDIT_HTML, MODE_EDIT_MD, + MODE_EDIT_TXT, MODE_MATHML, MODE_SELECTION, MODE_SOURCE, MODE_SVG, + ONLY_EDITABLE, OPTIONS_OPEN, PATH_OPTIONS_PAGE, PROCESS_CHILD, SYNC_AUTO, + SYNC_AUTO_URL, TMP_FILES_PB, TMP_FILES_PB_REMOVE, TMP_FILE_CREATE, + TMP_FILE_DATA_PORT, TMP_FILE_DATA_REMOVE, TMP_FILE_GET, TMP_FILE_REQ, + TMP_FILE_RES, VARS_SET, WARN_COLOR, WARN_TEXT } from './constant.js'; /* api */ @@ -900,15 +900,35 @@ export const handleCmd = async (cmd, tab) => { } let func; switch (cmd) { + case EDIT_HTML: + case EDIT_MD: + case EDIT_TXT: case EDITOR_EXEC: { if (!tab) { tab = await getActiveTab(); } const { id } = tab; if (tabList.has(id)) { - func = sendMessage(id, { - [CONTENT_GET]: { tab } - }); + if (cmd === EDITOR_EXEC) { + func = sendMessage(id, { + [CONTENT_GET]: { tab } + }); + } else { + let menuItemId; + if (cmd === EDIT_HTML) { + menuItemId = MODE_EDIT_HTML; + } else if (cmd === EDIT_MD) { + menuItemId = MODE_EDIT_MD; + } else { + menuItemId = MODE_EDIT_TXT; + } + const info = { + menuItemId + }; + func = sendMessage(id, { + [CONTENT_GET]: { info, tab } + }); + } } break; }