"use strict";var d=Object.defineProperty;var c=(t,n,e)=>n in t?d(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var s=(t,n,e)=>(c(t,typeof n!="symbol"?n+"":n,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("../../../../parchment@3.0.0/node_modules/parchment/dist/parchment.js"),h=require("../core/module.js"),f=require("../core/quill.js"),g=/Mac/i.test(navigator.platform),u=100,y=t=>!!(t.key==="ArrowLeft"||t.key==="ArrowRight"||t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="Home"||g&&t.key==="a"&&t.ctrlKey===!0);class A extends h.default{constructor(e,r){super(e,r);s(this,"isListening",!1);s(this,"selectionChangeDeadline",0);this.handleArrowKeys(),this.handleNavigationShortcuts()}handleArrowKeys(){this.quill.keyboard.addBinding({key:["ArrowLeft","ArrowRight"],offset:0,shiftKey:null,handler(e,r){let{line:i,event:o}=r;if(!(i instanceof l.ParentBlot)||!i.uiNode)return!0;const a=getComputedStyle(i.domNode).direction==="rtl";return a&&o.key!=="ArrowRight"||!a&&o.key!=="ArrowLeft"?!0:(this.quill.setSelection(e.index-1,e.length+(o.shiftKey?1:0),f.default.sources.USER),!1)}})}handleNavigationShortcuts(){this.quill.root.addEventListener("keydown",e=>{!e.defaultPrevented&&y(e)&&this.ensureListeningToSelectionChange()})}ensureListeningToSelectionChange(){if(this.selectionChangeDeadline=Date.now()+u,this.isListening)return;this.isListening=!0;const e=()=>{this.isListening=!1,Date.now()<=this.selectionChangeDeadline&&this.handleSelectionChange()};document.addEventListener("selectionchange",e,{once:!0})}handleSelectionChange(){const e=document.getSelection();if(!e)return;const r=e.getRangeAt(0);if(r.collapsed!==!0||r.startOffset!==0)return;const i=this.quill.scroll.find(r.startContainer);if(!(i instanceof l.ParentBlot)||!i.uiNode)return;const o=document.createRange();o.setStartAfter(i.uiNode),o.setEndAfter(i.uiNode),e.removeAllRanges(),e.addRange(o)}}exports.TTL_FOR_VALID_SELECTION_CHANGE=u;exports.default=A;
