1/*  DokuWiki MoaiEditor Cm_watcher.js file
2    Version : 0.5 (May 5, 2026)
3    Author  : MoaiTools <info@moaitools.org>
4    License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */
5
6/*
7*/
8MoaiEditor.CodemirrorWatcher = class extends MoaiEditor.WatchTextChanges {
9
10    getTextLines() {
11        return this.outer.editor.getValue().split("\n");
12    }
13    // ────────────────────────────────────
14    debug() {
15
16        // Exit if debugline is not enabled
17        const line = document.querySelector("#moai__debug div:nth-child(2)");
18        if (!line) return;
19
20        var msg = '';
21
22        // Monitor line 424 reported height
23        msg += parseInt(this.outer.editor.heightAtLine(423, 'local'));
24        //const top = this.editor.heightAtLine(0, 'local');
25
26        // Num rendered lines
27        var lines = document.querySelectorAll(".CodeMirror-code .CodeMirror-line ");
28        msg += " #" + lines.length;
29
30        // Get viewport
31        const vp = this.outer.editor.getViewport();
32        msg += " [" + vp.from + "-" + vp.to + "]";
33        //const top = this.editor.heightAtLine(0, 'local');
34
35        // Scroll
36        var content = document.querySelector(".CodeMirror-scroll");
37        msg += " ↓" + parseInt(content.scrollTop);
38
39        // Height
40        var content = document.querySelector(".CodeMirror-sizer");
41        msg += " ↕" + content.getBoundingClientRect().height;
42
43        // Show
44        const elapsed = '<span style="opacity:0.2">'+(Date.now()-this.last).toString().padStart(4," ")+'</span>';
45        const text = msg;
46        //line.innerHTML = text;
47        line.title = 'CM ';
48    }
49
50}; // End Class
51