/* DokuWiki MoaiEditor Scroll_to.js file Version : 0.5b (2026-05-08) Author : MoaiTools License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ /* */ MoaiEditor.WatchSelection = class { constructor(outer) { // Arguments this.outer = outer; // Variables this.selection = {start:null, end:null}; // Objects this.timer = new MoaiEditor.Timer(); // Intervals this.interval = setInterval(this.onInterval.bind(this), 200); } // ──────────────────────────────────── onInterval() { // Return if the parent is disabled if (!this.outer.enabled) return; // Return if not enough time has elapsed if (!this.timer.due()) return; // Return if the editor is not enabled and ready if (!moaiEditor.layoutReady) return; // Check for cursor/selection change this.checkSelectionChange(); // Optional debug actions this.debug(); } // ──────────────────────────────────── onInput() { this.timer.resetPeriod(); this.timer.restart(); this.checkSelectionChange(); } // ──────────────────────────────────── checkSelectionChange() { const start = this.outer.textarea.selectionStart; const end = this.outer.textarea.selectionEnd; if (start != this.selection.start || end != this.selection.end) { this.selection = {start:start, end:end}; this.timer.resetPeriod(); // Start checking more frequently for changes const coords = this.getCoords(start); //console.warn(this.selection); //console.warn(this.getCoords(start)); const string = this.outer.watcher.string; //console.warn(string[start]+" "); } } // ──────────────────────────────────── getCoords(pos) { var i = 0; var row = 0; for (let line of this.outer.watcher.lines) { const end = i + line.length + 1; if (pos < end) return {row:row, col:pos-i}; i = end; row += 1; } } // ──────────────────────────────────── debug() { // Placeholder } }; // End Class