Loading
function(e,t,n){"use strict";n.d(t,{A:()=>f,j:()=>h});var l=n(877413),i=n.n(l),s=n(284009),r=n.n(s),a=n(186306),o=n(339871),c=n(35277),u=n(820066),d=n(652215);function h(e,t){let{cmd:n=!1,ctrl:l=!1,alt:i=!1,shift:s=!1}=t;return(null==n||e.metaKey===n)&&(null==l||e.ctrlKey===l)&&(null==i||e.altKey===i)&&(null==s||e.shiftKey===s)}let m=e=>{let t=u.VW.getCurrentBlock(e);if(null!=t){let n=u.VW.start(e,t[1]);return c.b.select(e,{anchor:n,focus:n}),!0}return!1},p=e=>{let t=u.VW.getCurrentBlock(e);if(null!=t){let n=u.VW.end(e,t[1]);return c.b.select(e,{anchor:n,focus:n}),!0}return!1};function f(e){return e.onKeyDown=t=>{let n=e.isMac;switch(t.which){case d.Ks6.B:if(!u.VW.isEditorEmpty(e)&&h(t,{ctrl:!n,cmd:n}))return(0,o.Px)(e,"bold"),!0;break;case d.Ks6.I:if(!u.VW.isEditorEmpty(e)&&h(t,{ctrl:!n,cmd:n}))return(0,o.Px)(e,"italics"),!0;break;case d.Ks6.U:if(!u.VW.isEditorEmpty(e)&&h(t,{ctrl:!n,cmd:n}))return(0,o.Px)(e,"underline"),!0;break;case d.Ks6.S:if(!u.VW.isEditorEmpty(e)&&h(t,{ctrl:!n,cmd:n,shift:!0}))return(0,o.Px)(e,"strikethrough"),!0;break;case d.Ks6.TAB:if(null!=e.selection&&h(t,{shift:null})){let[n,l]=u.ZF.edges(e.selection),i=u.VW.blocks(e).slice(n.path[0],l.path[0]+1),s=!0;for(let[e]of i)if("line"!==e.type||!e.codeBlockState?.isInCodeBlock){s=!1;break}if(s){if(!t.shiftKey&&u.ZF.isCollapsed(e.selection))return c.b.insertText(e," "),!0;let n=!t.shiftKey;return a.o.withSingleEntry(e,()=>{let t=e.selection?.anchor??u.VW.start(e,[]),l=e.selection?.focus??u.VW.end(e,[]);for(let[s,r]of i){let i=s.children[0];if(!u.l5.isText(i))continue;let a=u.PW.child(r,0),o={path:a,offset:0};if(n)c.b.insertText(e," ",{at:o}),u.PW.equals(t.path,a)&&0!==t.offset&&(t={path:a,offset:t.offset+2}),u.PW.equals(l.path,a)&&0!==l.offset&&(l={path:a,offset:l.offset+2});else if(i.text.startsWith(" ")){let n={path:u.PW.child(r,0),offset:2};c.b.delete(e,{at:{anchor:o,focus:n}}),u.PW.equals(t.path,a)&&(t={path:a,offset:Math.max(0,t.offset-2)}),u.PW.equals(l.path,a)&&(l={path:a,offset:Math.max(0,l.offset-2)})}}c.b.select(e,{anchor:t,focus:l})}),!0}}break;case d.Ks6.ARROW_LEFT:case d.Ks6.ARROW_RIGHT:{let l;if(h(t,{shift:null}))l="character";else if(h(t,{ctrl:!n,alt:n,shift:null}))l="word";else if(n&&h(t,{cmd:!0,shift:null}))return!1;else return!1;let s=e.children[e.selection?.focus?.path[0]??0],r="rtl"===i()(u.AS.string(s)),a=t.which===d.Ks6.ARROW_LEFT==!r;return c.b.keyboardMove(e,{reverse:a,unit:l,edge:t.shiftKey?"focus":void 0}),!0}case d.Ks6.A:if(n&&h(t,{ctrl:!0})&&m(e))return!0;break;case d.Ks6.E:if(n&&h(t,{ctrl:!0})&&p(e))return!0;break;case d.Ks6.HOME:if(h(t,{shift:!1,ctrl:!1})&&m(e))return!0;break;case d.Ks6.END:if(h(t,{shift:!1,ctrl:!1})&&p(e))return!0;break;case d.Ks6.BACKSPACE:case d.Ks6.DELETE:case d.Ks6.K:let l=t.which===d.Ks6.BACKSPACE;if((!n&&t.which!==d.Ks6.K&&h(t,{ctrl:!0,shift:!0})||n&&t.which!==d.Ks6.K&&h(t,{cmd:!0})||n&&t.which===d.Ks6.K&&h(t,{ctrl:!0}))&&null!=e.selection){let[t,n]=u.ZF.edges(e.selection),[i,s]=u.VW.node(e,[l?t.path[0]:n.path[0]]);if(r()(u.VW.isBlock(e,i),"Top-most node of selection is not a block"),l&&!u.Kh.isAtStart(t,[i,s])||!l&&!u.Kh.isAtEnd(n,[i,s]))return l?e.deleteBackward("line"):e.deleteForward("line"),!0}}return!1},e}}