comparison .cms/lib/codemirror/src/display/Display.js @ 0:78edf6b517a0 draft

24.10
author Coffee CMS <info@coffee-cms.ru>
date Fri, 11 Oct 2024 22:40:23 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:78edf6b517a0
1 import { gecko, ie, ie_version, mobile, webkit, chrome, chrome_version } from "../util/browser.js"
2 import { elt, eltP } from "../util/dom.js"
3 import { scrollerGap } from "../util/misc.js"
4 import { getGutters, renderGutters } from "./gutters.js"
5
6 // The display handles the DOM integration, both for input reading
7 // and content drawing. It holds references to DOM nodes and
8 // display-related state.
9
10 export function Display(place, doc, input, options) {
11 let d = this
12 this.input = input
13
14 // Covers bottom-right square when both scrollbars are present.
15 d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
16 d.scrollbarFiller.setAttribute("cm-not-content", "true")
17 // Covers bottom of gutter when coverGutterNextToScrollbar is on
18 // and h scrollbar is present.
19 d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
20 d.gutterFiller.setAttribute("cm-not-content", "true")
21 // Will contain the actual code, positioned to cover the viewport.
22 d.lineDiv = eltP("div", null, "CodeMirror-code")
23 // Elements are added to these to represent selection and cursors.
24 d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
25 d.cursorDiv = elt("div", null, "CodeMirror-cursors")
26 // A visibility: hidden element used to find the size of things.
27 d.measure = elt("div", null, "CodeMirror-measure")
28 // When lines outside of the viewport are measured, they are drawn in this.
29 d.lineMeasure = elt("div", null, "CodeMirror-measure")
30 // Wraps everything that needs to exist inside the vertically-padded coordinate system
31 d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
32 null, "position: relative; outline: none")
33 let lines = eltP("div", [d.lineSpace], "CodeMirror-lines")
34 // Moved around its parent to cover visible view.
35 d.mover = elt("div", [lines], null, "position: relative")
36 // Set to the height of the document, allowing scrolling.
37 d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
38 d.sizerWidth = null
39 // Behavior of elts with overflow: auto and padding is
40 // inconsistent across browsers. This is used to ensure the
41 // scrollable area is big enough.
42 d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
43 // Will contain the gutters, if any.
44 d.gutters = elt("div", null, "CodeMirror-gutters")
45 d.lineGutter = null
46 // Actual scrollable element.
47 d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
48 d.scroller.setAttribute("tabIndex", "-1")
49 // The element in which the editor lives.
50 d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
51 // See #6982. FIXME remove when this has been fixed for a while in Chrome
52 if (chrome && chrome_version >= 105) d.wrapper.style.clipPath = "inset(0px)"
53
54 // This attribute is respected by automatic translation systems such as Google Translate,
55 // and may also be respected by tools used by human translators.
56 d.wrapper.setAttribute('translate', 'no')
57
58 // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
59 if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
60 if (!webkit && !(gecko && mobile)) d.scroller.draggable = true
61
62 if (place) {
63 if (place.appendChild) place.appendChild(d.wrapper)
64 else place(d.wrapper)
65 }
66
67 // Current rendered range (may be bigger than the view window).
68 d.viewFrom = d.viewTo = doc.first
69 d.reportedViewFrom = d.reportedViewTo = doc.first
70 // Information about the rendered lines.
71 d.view = []
72 d.renderedView = null
73 // Holds info about a single rendered line when it was rendered
74 // for measurement, while not in view.
75 d.externalMeasured = null
76 // Empty space (in pixels) above the view
77 d.viewOffset = 0
78 d.lastWrapHeight = d.lastWrapWidth = 0
79 d.updateLineNumbers = null
80
81 d.nativeBarWidth = d.barHeight = d.barWidth = 0
82 d.scrollbarsClipped = false
83
84 // Used to only resize the line number gutter when necessary (when
85 // the amount of lines crosses a boundary that makes its width change)
86 d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
87 // Set to true when a non-horizontal-scrolling line widget is
88 // added. As an optimization, line widget aligning is skipped when
89 // this is false.
90 d.alignWidgets = false
91
92 d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
93
94 // Tracks the maximum line length so that the horizontal scrollbar
95 // can be kept static when scrolling.
96 d.maxLine = null
97 d.maxLineLength = 0
98 d.maxLineChanged = false
99
100 // Used for measuring wheel scrolling granularity
101 d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
102
103 // True when shift is held down.
104 d.shift = false
105
106 // Used to track whether anything happened since the context menu
107 // was opened.
108 d.selForContextMenu = null
109
110 d.activeTouch = null
111
112 d.gutterSpecs = getGutters(options.gutters, options.lineNumbers)
113 renderGutters(d)
114
115 input.init(d)
116 }