即按 Alt + X 的时候既标注你颜色又加粗字体
相关帖子
-
wilsons • • 1付费者 捐赠者
alt+z 行吗?alt+x 和思源冲突,调不出来
// alt+z 给文字加粗和标记 (()=>{ // 监听键盘按下alt+z事件 document.addEventListener('keydown', function(event) { // 检查是否按下了 Alt 键以及物理按键是 'KeyZ' if ( event.altKey && // 按下了 Alt 键 event.code === 'KeyZ' && // 物理按键是 Z !event.shiftKey && // 未按下 Shift 键 !event.ctrlKey && // 未按下 Ctrl 键 !event.metaKey // 未按下 Meta 键 ) { // 阻止默认行为(如果有必要) event.preventDefault(); // 获取protyle const protyle = getProtyle(); // 给文字加粗 protyle.toolbar.setInlineMark(protyle, 'strong', "toolbar"); // 给文字标记 protyle.toolbar.setInlineMark(protyle, 'mark', "toolbar"); } }); function getProtyle() { try { if(document.getElementById("sidebar")) return siyuan.mobile.editor.protyle; const currDoc = siyuan?.layout?.centerLayout?.children.map(item=>item.children.find(item=>item.headElement?.classList.contains('item--focus') && (item.panelElement.closest('.layout__wnd--active')||item.panelElement.closest('[data-type="wnd"]')))).find(item=>item); return currDoc?.model.editor.protyle; } catch(e) { console.error(e); return null; } } })();
-
alt+z 行吗?alt+x 和思源冲突,调不出来
// alt+z 给文字加粗和标记 (()=>{ // 监听键盘按下alt+z事件 document.addEventListener('keydown', function(event) { // 检查是否按下了 Alt 键以及物理按键是 'KeyZ' if ( event.altKey && // 按下了 Alt 键 event.code === 'KeyZ' && // 物理按键是 Z !event.shiftKey && // 未按下 Shift 键 !event.ctrlKey && // 未按下 Ctrl 键 !event.metaKey // 未按下 Meta 键 ) { // 阻止默认行为(如果有必要) event.preventDefault(); // 获取protyle const protyle = getProtyle(); // 给文字加粗 protyle.toolbar.setInlineMark(protyle, 'strong', "toolbar"); // 给文字标记 protyle.toolbar.setInlineMark(protyle, 'mark', "toolbar"); } }); function getProtyle() { try { if(document.getElementById("sidebar")) return siyuan.mobile.editor.protyle; const currDoc = siyuan?.layout?.centerLayout?.children.map(item=>item.children.find(item=>item.headElement?.classList.contains('item--focus') && (item.panelElement.closest('.layout__wnd--active')||item.panelElement.closest('[data-type="wnd"]')))).find(item=>item); return currDoc?.model.editor.protyle; } catch(e) { console.error(e); return null; } } })();
2 回复这个好像是和 mark 标记是一样的效果,所以我可以直接修改 mark 标记的 css 实现,但是只有一种颜色,也够用了Adaxi • -
-
-
-
alt+x 版
注意:
代码中加上这个 event.stopPropagation();可以阻止默认的 alt+x 最近使用样式的添加(默认已加上这个代码)
去掉这个代码,则会同时赋予 3 种样式,加粗,标记和最近样式
// alt+x 给文字加粗和标记 (()=>{ // 监听键盘按下alt+x事件 document.addEventListener('keydown', function(event) { // 检查是否按下了 Alt 键以及物理按键是 'KeyX' if ( event.altKey && // 按下了 Alt 键 event.code === 'KeyX' && // 物理按键是 X !event.shiftKey && // 未按下 Shift 键 !event.ctrlKey && // 未按下 Ctrl 键 !event.metaKey // 未按下 Meta 键 ) { // 阻止默认行为(如果有必要) event.preventDefault(); // 阻止冒泡,不加这个会和思源的alt+x重合,出现三种效果 event.stopPropagation(); // 获取protyle const protyle = getProtyle(); // 给文字加粗 protyle.toolbar.setInlineMark(protyle, 'strong', "toolbar"); // 给文字标记 protyle.toolbar.setInlineMark(protyle, 'mark', "toolbar"); } },true); function getProtyle() { try { if(document.getElementById("sidebar")) return siyuan.mobile.editor.protyle; const currDoc = siyuan?.layout?.centerLayout?.children.map(item=>item.children.find(item=>item.headElement?.classList.contains('item--focus') && (item.panelElement.closest('.layout__wnd--active')||item.panelElement.closest('[data-type="wnd"]')))).find(item=>item); return currDoc?.model.editor.protyle; } catch(e) { console.error(e); return null; } } })();
-
这个好像是和 mark 标记是一样的效果,所以我可以直接修改 mark 标记的 css 实现,但是只有一种颜色,也够用了
这个 protyle.toolbar.setInlineMark(protyle, 'mark', "toolbar"); mark 这个参数可以任意改,工具栏上的"strong", "em", "s", "code", "mark", "tag", "u", "sup", "clear", "sub", "kbd"样式都支持。
如果想要改文字颜色或背景色也可以
比如:
protyle.toolbar.setInlineMark(protyle, "text", "range", {type:'color', color:'var(--b3-font-color8)'}); protyle.toolbar.setInlineMark(protyle, "text", "range", {type:'backgroundColor', color:'var(--b3-font-background2)'});
当然,你用自己的方法实现也可以的,条条大路通罗马。
谢谢提点Adaxi •