@muze-nl/simplystore 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +8 -0
- package/.github/workflows/docker-build.yml +45 -0
- package/.gitignore~ +1 -0
- package/Dockerfile +60 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/data.jsontag +20 -0
- package/design/access-management.md +25 -0
- package/design/acid.md +31 -0
- package/design/commands.md +25 -0
- package/design/identity.md +71 -0
- package/design/immutability.md +26 -0
- package/design/jsontag-selector.md +365 -0
- package/design/multitasking.md +13 -0
- package/design/thoughts.md +32 -0
- package/docs/docker.md +129 -0
- package/package.json +29 -0
- package/package.json~ +29 -0
- package/src/run.mjs +3 -0
- package/src/server.mjs +323 -0
- package/src/triplestore.mjs +182 -0
- package/www/assets/css/style.css +2296 -0
- package/www/assets/feather-sprite.svg +1 -0
- package/www/assets/img/simplystore-narrow-white.svg +138 -0
- package/www/assets/img/simplystore-narrow.svg +138 -0
- package/www/assets/img/simplystore-white.svg +153 -0
- package/www/assets/img/simplystore.svg +153 -0
- package/www/codemirror/AUTHORS +979 -0
- package/www/codemirror/CHANGELOG.md +2208 -0
- package/www/codemirror/CONTRIBUTING.md +92 -0
- package/www/codemirror/LICENSE +21 -0
- package/www/codemirror/README.md +47 -0
- package/www/codemirror/addon/comment/comment.js +211 -0
- package/www/codemirror/addon/comment/continuecomment.js +114 -0
- package/www/codemirror/addon/dialog/dialog.css +32 -0
- package/www/codemirror/addon/dialog/dialog.js +163 -0
- package/www/codemirror/addon/display/autorefresh.js +47 -0
- package/www/codemirror/addon/display/fullscreen.css +6 -0
- package/www/codemirror/addon/display/fullscreen.js +41 -0
- package/www/codemirror/addon/display/panel.js +133 -0
- package/www/codemirror/addon/display/placeholder.js +78 -0
- package/www/codemirror/addon/display/rulers.js +51 -0
- package/www/codemirror/addon/edit/closebrackets.js +201 -0
- package/www/codemirror/addon/edit/closetag.js +185 -0
- package/www/codemirror/addon/edit/continuelist.js +101 -0
- package/www/codemirror/addon/edit/matchbrackets.js +160 -0
- package/www/codemirror/addon/edit/matchtags.js +66 -0
- package/www/codemirror/addon/edit/trailingspace.js +27 -0
- package/www/codemirror/addon/fold/brace-fold.js +119 -0
- package/www/codemirror/addon/fold/comment-fold.js +59 -0
- package/www/codemirror/addon/fold/foldcode.js +159 -0
- package/www/codemirror/addon/fold/foldgutter.css +20 -0
- package/www/codemirror/addon/fold/foldgutter.js +169 -0
- package/www/codemirror/addon/fold/indent-fold.js +48 -0
- package/www/codemirror/addon/fold/markdown-fold.js +49 -0
- package/www/codemirror/addon/fold/xml-fold.js +184 -0
- package/www/codemirror/addon/hint/anyword-hint.js +41 -0
- package/www/codemirror/addon/hint/css-hint.js +66 -0
- package/www/codemirror/addon/hint/html-hint.js +351 -0
- package/www/codemirror/addon/hint/javascript-hint.js +162 -0
- package/www/codemirror/addon/hint/show-hint.css +37 -0
- package/www/codemirror/addon/hint/show-hint.js +523 -0
- package/www/codemirror/addon/hint/sql-hint.js +304 -0
- package/www/codemirror/addon/hint/xml-hint.js +132 -0
- package/www/codemirror/addon/lint/coffeescript-lint.js +47 -0
- package/www/codemirror/addon/lint/css-lint.js +40 -0
- package/www/codemirror/addon/lint/html-lint.js +59 -0
- package/www/codemirror/addon/lint/javascript-lint.js +65 -0
- package/www/codemirror/addon/lint/json-lint.js +40 -0
- package/www/codemirror/addon/lint/lint.css +79 -0
- package/www/codemirror/addon/lint/lint.js +291 -0
- package/www/codemirror/addon/lint/yaml-lint.js +41 -0
- package/www/codemirror/addon/merge/merge.css +119 -0
- package/www/codemirror/addon/merge/merge.js +1018 -0
- package/www/codemirror/addon/mode/loadmode.js +66 -0
- package/www/codemirror/addon/mode/multiplex.js +136 -0
- package/www/codemirror/addon/mode/multiplex_test.js +49 -0
- package/www/codemirror/addon/mode/overlay.js +90 -0
- package/www/codemirror/addon/mode/simple.js +216 -0
- package/www/codemirror/addon/runmode/colorize.js +40 -0
- package/www/codemirror/addon/runmode/runmode-standalone.js +334 -0
- package/www/codemirror/addon/runmode/runmode.js +76 -0
- package/www/codemirror/addon/runmode/runmode.node.js +329 -0
- package/www/codemirror/addon/scroll/annotatescrollbar.js +128 -0
- package/www/codemirror/addon/scroll/scrollpastend.js +48 -0
- package/www/codemirror/addon/scroll/simplescrollbars.css +66 -0
- package/www/codemirror/addon/scroll/simplescrollbars.js +152 -0
- package/www/codemirror/addon/search/jump-to-line.js +53 -0
- package/www/codemirror/addon/search/match-highlighter.js +167 -0
- package/www/codemirror/addon/search/matchesonscrollbar.css +8 -0
- package/www/codemirror/addon/search/matchesonscrollbar.js +97 -0
- package/www/codemirror/addon/search/search.js +295 -0
- package/www/codemirror/addon/search/searchcursor.js +305 -0
- package/www/codemirror/addon/selection/active-line.js +72 -0
- package/www/codemirror/addon/selection/mark-selection.js +119 -0
- package/www/codemirror/addon/selection/selection-pointer.js +98 -0
- package/www/codemirror/addon/tern/tern.css +87 -0
- package/www/codemirror/addon/tern/tern.js +756 -0
- package/www/codemirror/addon/tern/worker.js +44 -0
- package/www/codemirror/addon/wrap/hardwrap.js +160 -0
- package/www/codemirror/bin/source-highlight +48 -0
- package/www/codemirror/keymap/emacs.js +545 -0
- package/www/codemirror/keymap/sublime.js +720 -0
- package/www/codemirror/keymap/vim.js +5978 -0
- package/www/codemirror/lib/codemirror.css +344 -0
- package/www/codemirror/lib/codemirror.js +9874 -0
- package/www/codemirror/mode/apl/apl.js +174 -0
- package/www/codemirror/mode/asciiarmor/asciiarmor.js +74 -0
- package/www/codemirror/mode/asn.1/asn.1.js +204 -0
- package/www/codemirror/mode/asterisk/asterisk.js +220 -0
- package/www/codemirror/mode/brainfuck/brainfuck.js +85 -0
- package/www/codemirror/mode/clike/clike.js +940 -0
- package/www/codemirror/mode/clojure/clojure.js +292 -0
- package/www/codemirror/mode/cmake/cmake.js +97 -0
- package/www/codemirror/mode/cobol/cobol.js +255 -0
- package/www/codemirror/mode/coffeescript/coffeescript.js +359 -0
- package/www/codemirror/mode/commonlisp/commonlisp.js +125 -0
- package/www/codemirror/mode/crystal/crystal.js +433 -0
- package/www/codemirror/mode/css/css.js +862 -0
- package/www/codemirror/mode/cypher/cypher.js +152 -0
- package/www/codemirror/mode/d/d.js +223 -0
- package/www/codemirror/mode/dart/dart.js +166 -0
- package/www/codemirror/mode/diff/diff.js +47 -0
- package/www/codemirror/mode/django/django.js +356 -0
- package/www/codemirror/mode/dockerfile/dockerfile.js +211 -0
- package/www/codemirror/mode/dtd/dtd.js +142 -0
- package/www/codemirror/mode/dylan/dylan.js +352 -0
- package/www/codemirror/mode/ebnf/ebnf.js +195 -0
- package/www/codemirror/mode/ecl/ecl.js +206 -0
- package/www/codemirror/mode/eiffel/eiffel.js +160 -0
- package/www/codemirror/mode/elm/elm.js +245 -0
- package/www/codemirror/mode/erlang/erlang.js +619 -0
- package/www/codemirror/mode/factor/factor.js +85 -0
- package/www/codemirror/mode/fcl/fcl.js +173 -0
- package/www/codemirror/mode/forth/forth.js +180 -0
- package/www/codemirror/mode/fortran/fortran.js +188 -0
- package/www/codemirror/mode/gas/gas.js +353 -0
- package/www/codemirror/mode/gfm/gfm.js +129 -0
- package/www/codemirror/mode/gherkin/gherkin.js +178 -0
- package/www/codemirror/mode/go/go.js +187 -0
- package/www/codemirror/mode/groovy/groovy.js +247 -0
- package/www/codemirror/mode/haml/haml.js +161 -0
- package/www/codemirror/mode/handlebars/handlebars.js +70 -0
- package/www/codemirror/mode/haskell/haskell.js +268 -0
- package/www/codemirror/mode/haskell-literate/haskell-literate.js +43 -0
- package/www/codemirror/mode/haxe/haxe.js +515 -0
- package/www/codemirror/mode/htmlembedded/htmlembedded.js +37 -0
- package/www/codemirror/mode/htmlmixed/htmlmixed.js +153 -0
- package/www/codemirror/mode/http/http.js +113 -0
- package/www/codemirror/mode/idl/idl.js +290 -0
- package/www/codemirror/mode/javascript/javascript.js +960 -0
- package/www/codemirror/mode/jinja2/jinja2.js +193 -0
- package/www/codemirror/mode/jsx/jsx.js +148 -0
- package/www/codemirror/mode/julia/julia.js +390 -0
- package/www/codemirror/mode/livescript/livescript.js +280 -0
- package/www/codemirror/mode/lua/lua.js +160 -0
- package/www/codemirror/mode/markdown/markdown.js +886 -0
- package/www/codemirror/mode/mathematica/mathematica.js +176 -0
- package/www/codemirror/mode/mbox/mbox.js +129 -0
- package/www/codemirror/mode/meta.js +221 -0
- package/www/codemirror/mode/mirc/mirc.js +193 -0
- package/www/codemirror/mode/mllike/mllike.js +359 -0
- package/www/codemirror/mode/modelica/modelica.js +245 -0
- package/www/codemirror/mode/mscgen/mscgen.js +175 -0
- package/www/codemirror/mode/mumps/mumps.js +148 -0
- package/www/codemirror/mode/nginx/nginx.js +178 -0
- package/www/codemirror/mode/nsis/nsis.js +95 -0
- package/www/codemirror/mode/ntriples/ntriples.js +195 -0
- package/www/codemirror/mode/octave/octave.js +139 -0
- package/www/codemirror/mode/oz/oz.js +252 -0
- package/www/codemirror/mode/pascal/pascal.js +136 -0
- package/www/codemirror/mode/pegjs/pegjs.js +111 -0
- package/www/codemirror/mode/perl/perl.js +836 -0
- package/www/codemirror/mode/php/php.js +234 -0
- package/www/codemirror/mode/pig/pig.js +178 -0
- package/www/codemirror/mode/powershell/powershell.js +398 -0
- package/www/codemirror/mode/properties/properties.js +78 -0
- package/www/codemirror/mode/protobuf/protobuf.js +72 -0
- package/www/codemirror/mode/pug/pug.js +591 -0
- package/www/codemirror/mode/puppet/puppet.js +220 -0
- package/www/codemirror/mode/python/python.js +402 -0
- package/www/codemirror/mode/q/q.js +139 -0
- package/www/codemirror/mode/r/r.js +190 -0
- package/www/codemirror/mode/rpm/changes/index.html +66 -0
- package/www/codemirror/mode/rpm/rpm.js +109 -0
- package/www/codemirror/mode/rst/rst.js +557 -0
- package/www/codemirror/mode/ruby/ruby.js +303 -0
- package/www/codemirror/mode/rust/rust.js +72 -0
- package/www/codemirror/mode/sas/sas.js +303 -0
- package/www/codemirror/mode/sass/sass.js +459 -0
- package/www/codemirror/mode/scheme/scheme.js +284 -0
- package/www/codemirror/mode/shell/shell.js +168 -0
- package/www/codemirror/mode/sieve/sieve.js +193 -0
- package/www/codemirror/mode/slim/slim.js +575 -0
- package/www/codemirror/mode/smalltalk/smalltalk.js +168 -0
- package/www/codemirror/mode/smarty/smarty.js +225 -0
- package/www/codemirror/mode/solr/solr.js +104 -0
- package/www/codemirror/mode/soy/soy.js +665 -0
- package/www/codemirror/mode/sparql/sparql.js +184 -0
- package/www/codemirror/mode/spreadsheet/spreadsheet.js +112 -0
- package/www/codemirror/mode/sql/sql.js +525 -0
- package/www/codemirror/mode/stex/stex.js +264 -0
- package/www/codemirror/mode/stylus/stylus.js +775 -0
- package/www/codemirror/mode/swift/swift.js +221 -0
- package/www/codemirror/mode/tcl/tcl.js +140 -0
- package/www/codemirror/mode/textile/textile.js +469 -0
- package/www/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
- package/www/codemirror/mode/tiddlywiki/tiddlywiki.js +308 -0
- package/www/codemirror/mode/tiki/tiki.css +26 -0
- package/www/codemirror/mode/tiki/tiki.js +312 -0
- package/www/codemirror/mode/toml/toml.js +88 -0
- package/www/codemirror/mode/tornado/tornado.js +68 -0
- package/www/codemirror/mode/troff/troff.js +84 -0
- package/www/codemirror/mode/ttcn/ttcn.js +283 -0
- package/www/codemirror/mode/ttcn-cfg/ttcn-cfg.js +214 -0
- package/www/codemirror/mode/turtle/turtle.js +162 -0
- package/www/codemirror/mode/twig/twig.js +141 -0
- package/www/codemirror/mode/vb/vb.js +275 -0
- package/www/codemirror/mode/vbscript/vbscript.js +350 -0
- package/www/codemirror/mode/velocity/velocity.js +202 -0
- package/www/codemirror/mode/verilog/verilog.js +781 -0
- package/www/codemirror/mode/vhdl/vhdl.js +189 -0
- package/www/codemirror/mode/vue/vue.js +77 -0
- package/www/codemirror/mode/wast/wast.js +132 -0
- package/www/codemirror/mode/webidl/webidl.js +195 -0
- package/www/codemirror/mode/xml/xml.js +417 -0
- package/www/codemirror/mode/xquery/xquery.js +448 -0
- package/www/codemirror/mode/yacas/yacas.js +204 -0
- package/www/codemirror/mode/yaml/yaml.js +120 -0
- package/www/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js +72 -0
- package/www/codemirror/mode/z80/z80.js +116 -0
- package/www/codemirror/package.json +52 -0
- package/www/codemirror/rollup.config.js +52 -0
- package/www/codemirror/src/addon/runmode/codemirror-standalone.js +24 -0
- package/www/codemirror/src/addon/runmode/codemirror.node.js +21 -0
- package/www/codemirror/src/addon/runmode/runmode-standalone.js +2 -0
- package/www/codemirror/src/addon/runmode/runmode.node.js +2 -0
- package/www/codemirror/src/codemirror.js +3 -0
- package/www/codemirror/src/display/Display.js +116 -0
- package/www/codemirror/src/display/focus.js +50 -0
- package/www/codemirror/src/display/gutters.js +44 -0
- package/www/codemirror/src/display/highlight_worker.js +55 -0
- package/www/codemirror/src/display/line_numbers.js +48 -0
- package/www/codemirror/src/display/mode_state.js +22 -0
- package/www/codemirror/src/display/operations.js +206 -0
- package/www/codemirror/src/display/scroll_events.js +132 -0
- package/www/codemirror/src/display/scrollbars.js +194 -0
- package/www/codemirror/src/display/scrolling.js +186 -0
- package/www/codemirror/src/display/selection.js +173 -0
- package/www/codemirror/src/display/update_display.js +267 -0
- package/www/codemirror/src/display/update_line.js +189 -0
- package/www/codemirror/src/display/update_lines.js +82 -0
- package/www/codemirror/src/display/view_tracking.js +153 -0
- package/www/codemirror/src/edit/CodeMirror.js +217 -0
- package/www/codemirror/src/edit/commands.js +178 -0
- package/www/codemirror/src/edit/deleteNearSelection.js +30 -0
- package/www/codemirror/src/edit/drop_events.js +130 -0
- package/www/codemirror/src/edit/fromTextArea.js +61 -0
- package/www/codemirror/src/edit/global_events.js +45 -0
- package/www/codemirror/src/edit/key_events.js +163 -0
- package/www/codemirror/src/edit/legacy.js +62 -0
- package/www/codemirror/src/edit/main.js +69 -0
- package/www/codemirror/src/edit/methods.js +555 -0
- package/www/codemirror/src/edit/mouse_events.js +417 -0
- package/www/codemirror/src/edit/options.js +194 -0
- package/www/codemirror/src/edit/utils.js +7 -0
- package/www/codemirror/src/input/ContentEditableInput.js +546 -0
- package/www/codemirror/src/input/TextareaInput.js +380 -0
- package/www/codemirror/src/input/indent.js +71 -0
- package/www/codemirror/src/input/input.js +134 -0
- package/www/codemirror/src/input/keymap.js +147 -0
- package/www/codemirror/src/input/keynames.js +17 -0
- package/www/codemirror/src/input/movement.js +111 -0
- package/www/codemirror/src/line/highlight.js +284 -0
- package/www/codemirror/src/line/line_data.js +349 -0
- package/www/codemirror/src/line/pos.js +40 -0
- package/www/codemirror/src/line/saw_special_spans.js +10 -0
- package/www/codemirror/src/line/spans.js +390 -0
- package/www/codemirror/src/line/utils_line.js +85 -0
- package/www/codemirror/src/measurement/position_measurement.js +702 -0
- package/www/codemirror/src/measurement/widgets.js +26 -0
- package/www/codemirror/src/model/Doc.js +436 -0
- package/www/codemirror/src/model/change_measurement.js +61 -0
- package/www/codemirror/src/model/changes.js +339 -0
- package/www/codemirror/src/model/chunk.js +167 -0
- package/www/codemirror/src/model/document_data.js +112 -0
- package/www/codemirror/src/model/history.js +228 -0
- package/www/codemirror/src/model/line_widget.js +78 -0
- package/www/codemirror/src/model/mark_text.js +293 -0
- package/www/codemirror/src/model/selection.js +84 -0
- package/www/codemirror/src/model/selection_updates.js +216 -0
- package/www/codemirror/src/modes.js +96 -0
- package/www/codemirror/src/util/StringStream.js +90 -0
- package/www/codemirror/src/util/bidi.js +215 -0
- package/www/codemirror/src/util/browser.js +34 -0
- package/www/codemirror/src/util/dom.js +101 -0
- package/www/codemirror/src/util/event.js +103 -0
- package/www/codemirror/src/util/feature_detection.js +84 -0
- package/www/codemirror/src/util/misc.js +168 -0
- package/www/codemirror/src/util/operation_group.js +72 -0
- package/www/codemirror/theme/3024-day.css +41 -0
- package/www/codemirror/theme/3024-night.css +39 -0
- package/www/codemirror/theme/abbott.css +268 -0
- package/www/codemirror/theme/abcdef.css +32 -0
- package/www/codemirror/theme/ambiance-mobile.css +5 -0
- package/www/codemirror/theme/ambiance.css +74 -0
- package/www/codemirror/theme/ayu-dark.css +44 -0
- package/www/codemirror/theme/ayu-mirage.css +45 -0
- package/www/codemirror/theme/base16-dark.css +40 -0
- package/www/codemirror/theme/base16-light.css +38 -0
- package/www/codemirror/theme/bespin.css +34 -0
- package/www/codemirror/theme/blackboard.css +32 -0
- package/www/codemirror/theme/cobalt.css +25 -0
- package/www/codemirror/theme/colorforth.css +33 -0
- package/www/codemirror/theme/darcula.css +53 -0
- package/www/codemirror/theme/dracula.css +40 -0
- package/www/codemirror/theme/duotone-dark.css +35 -0
- package/www/codemirror/theme/duotone-light.css +36 -0
- package/www/codemirror/theme/eclipse.css +23 -0
- package/www/codemirror/theme/elegant.css +13 -0
- package/www/codemirror/theme/erlang-dark.css +34 -0
- package/www/codemirror/theme/gruvbox-dark.css +39 -0
- package/www/codemirror/theme/hopscotch.css +34 -0
- package/www/codemirror/theme/icecoder.css +43 -0
- package/www/codemirror/theme/idea.css +42 -0
- package/www/codemirror/theme/isotope.css +34 -0
- package/www/codemirror/theme/juejin.css +30 -0
- package/www/codemirror/theme/lesser-dark.css +47 -0
- package/www/codemirror/theme/liquibyte.css +95 -0
- package/www/codemirror/theme/lucario.css +37 -0
- package/www/codemirror/theme/material-darker.css +135 -0
- package/www/codemirror/theme/material-ocean.css +141 -0
- package/www/codemirror/theme/material-palenight.css +141 -0
- package/www/codemirror/theme/material.css +141 -0
- package/www/codemirror/theme/mbo.css +37 -0
- package/www/codemirror/theme/mdn-like.css +46 -0
- package/www/codemirror/theme/midnight.css +39 -0
- package/www/codemirror/theme/monokai.css +41 -0
- package/www/codemirror/theme/moxer.css +143 -0
- package/www/codemirror/theme/neat.css +12 -0
- package/www/codemirror/theme/neo.css +43 -0
- package/www/codemirror/theme/night.css +27 -0
- package/www/codemirror/theme/nord.css +42 -0
- package/www/codemirror/theme/oceanic-next.css +46 -0
- package/www/codemirror/theme/panda-syntax.css +85 -0
- package/www/codemirror/theme/paraiso-dark.css +38 -0
- package/www/codemirror/theme/paraiso-light.css +38 -0
- package/www/codemirror/theme/pastel-on-dark.css +52 -0
- package/www/codemirror/theme/railscasts.css +34 -0
- package/www/codemirror/theme/rubyblue.css +25 -0
- package/www/codemirror/theme/seti.css +44 -0
- package/www/codemirror/theme/shadowfox.css +52 -0
- package/www/codemirror/theme/solarized.css +165 -0
- package/www/codemirror/theme/ssms.css +16 -0
- package/www/codemirror/theme/the-matrix.css +30 -0
- package/www/codemirror/theme/tomorrow-night-bright.css +35 -0
- package/www/codemirror/theme/tomorrow-night-eighties.css +38 -0
- package/www/codemirror/theme/ttcn.css +64 -0
- package/www/codemirror/theme/twilight.css +32 -0
- package/www/codemirror/theme/vibrant-ink.css +34 -0
- package/www/codemirror/theme/xq-dark.css +53 -0
- package/www/codemirror/theme/xq-light.css +43 -0
- package/www/codemirror/theme/yeti.css +44 -0
- package/www/codemirror/theme/yonce.css +59 -0
- package/www/codemirror/theme/zenburn.css +37 -0
- package/www/index.html +216 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { sawCollapsedSpans } from "../line/saw_special_spans.js"
|
|
2
|
+
import { heightAtLine, visualLineEndNo, visualLineNo } from "../line/spans.js"
|
|
3
|
+
import { getLine, lineNumberFor } from "../line/utils_line.js"
|
|
4
|
+
import { displayHeight, displayWidth, getDimensions, paddingVert, scrollGap } from "../measurement/position_measurement.js"
|
|
5
|
+
import { mac, webkit } from "../util/browser.js"
|
|
6
|
+
import { activeElt, removeChildren, contains, win, doc } from "../util/dom.js"
|
|
7
|
+
import { hasHandler, signal } from "../util/event.js"
|
|
8
|
+
import { signalLater } from "../util/operation_group.js"
|
|
9
|
+
import { indexOf } from "../util/misc.js"
|
|
10
|
+
|
|
11
|
+
import { buildLineElement, updateLineForChanges } from "./update_line.js"
|
|
12
|
+
import { startWorker } from "./highlight_worker.js"
|
|
13
|
+
import { maybeUpdateLineNumberWidth } from "./line_numbers.js"
|
|
14
|
+
import { measureForScrollbars, updateScrollbars } from "./scrollbars.js"
|
|
15
|
+
import { updateSelection } from "./selection.js"
|
|
16
|
+
import { updateHeightsInViewport, visibleLines } from "./update_lines.js"
|
|
17
|
+
import { adjustView, countDirtyView, resetView } from "./view_tracking.js"
|
|
18
|
+
|
|
19
|
+
// DISPLAY DRAWING
|
|
20
|
+
|
|
21
|
+
export class DisplayUpdate {
|
|
22
|
+
constructor(cm, viewport, force) {
|
|
23
|
+
let display = cm.display
|
|
24
|
+
|
|
25
|
+
this.viewport = viewport
|
|
26
|
+
// Store some values that we'll need later (but don't want to force a relayout for)
|
|
27
|
+
this.visible = visibleLines(display, cm.doc, viewport)
|
|
28
|
+
this.editorIsHidden = !display.wrapper.offsetWidth
|
|
29
|
+
this.wrapperHeight = display.wrapper.clientHeight
|
|
30
|
+
this.wrapperWidth = display.wrapper.clientWidth
|
|
31
|
+
this.oldDisplayWidth = displayWidth(cm)
|
|
32
|
+
this.force = force
|
|
33
|
+
this.dims = getDimensions(cm)
|
|
34
|
+
this.events = []
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
signal(emitter, type) {
|
|
38
|
+
if (hasHandler(emitter, type))
|
|
39
|
+
this.events.push(arguments)
|
|
40
|
+
}
|
|
41
|
+
finish() {
|
|
42
|
+
for (let i = 0; i < this.events.length; i++)
|
|
43
|
+
signal.apply(null, this.events[i])
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function maybeClipScrollbars(cm) {
|
|
48
|
+
let display = cm.display
|
|
49
|
+
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
|
|
50
|
+
display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth
|
|
51
|
+
display.heightForcer.style.height = scrollGap(cm) + "px"
|
|
52
|
+
display.sizer.style.marginBottom = -display.nativeBarWidth + "px"
|
|
53
|
+
display.sizer.style.borderRightWidth = scrollGap(cm) + "px"
|
|
54
|
+
display.scrollbarsClipped = true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function selectionSnapshot(cm) {
|
|
59
|
+
if (cm.hasFocus()) return null
|
|
60
|
+
let active = activeElt(doc(cm))
|
|
61
|
+
if (!active || !contains(cm.display.lineDiv, active)) return null
|
|
62
|
+
let result = {activeElt: active}
|
|
63
|
+
if (window.getSelection) {
|
|
64
|
+
let sel = win(cm).getSelection()
|
|
65
|
+
if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
|
|
66
|
+
result.anchorNode = sel.anchorNode
|
|
67
|
+
result.anchorOffset = sel.anchorOffset
|
|
68
|
+
result.focusNode = sel.focusNode
|
|
69
|
+
result.focusOffset = sel.focusOffset
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function restoreSelection(snapshot) {
|
|
76
|
+
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(snapshot.activeElt.ownerDocument)) return
|
|
77
|
+
snapshot.activeElt.focus()
|
|
78
|
+
if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) &&
|
|
79
|
+
snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
|
|
80
|
+
let doc = snapshot.activeElt.ownerDocument
|
|
81
|
+
let sel = doc.defaultView.getSelection(), range = doc.createRange()
|
|
82
|
+
range.setEnd(snapshot.anchorNode, snapshot.anchorOffset)
|
|
83
|
+
range.collapse(false)
|
|
84
|
+
sel.removeAllRanges()
|
|
85
|
+
sel.addRange(range)
|
|
86
|
+
sel.extend(snapshot.focusNode, snapshot.focusOffset)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Does the actual updating of the line display. Bails out
|
|
91
|
+
// (returning false) when there is nothing to be done and forced is
|
|
92
|
+
// false.
|
|
93
|
+
export function updateDisplayIfNeeded(cm, update) {
|
|
94
|
+
let display = cm.display, doc = cm.doc
|
|
95
|
+
|
|
96
|
+
if (update.editorIsHidden) {
|
|
97
|
+
resetView(cm)
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Bail out if the visible area is already rendered and nothing changed.
|
|
102
|
+
if (!update.force &&
|
|
103
|
+
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
|
|
104
|
+
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
|
|
105
|
+
display.renderedView == display.view && countDirtyView(cm) == 0)
|
|
106
|
+
return false
|
|
107
|
+
|
|
108
|
+
if (maybeUpdateLineNumberWidth(cm)) {
|
|
109
|
+
resetView(cm)
|
|
110
|
+
update.dims = getDimensions(cm)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Compute a suitable new viewport (from & to)
|
|
114
|
+
let end = doc.first + doc.size
|
|
115
|
+
let from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first)
|
|
116
|
+
let to = Math.min(end, update.visible.to + cm.options.viewportMargin)
|
|
117
|
+
if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom)
|
|
118
|
+
if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo)
|
|
119
|
+
if (sawCollapsedSpans) {
|
|
120
|
+
from = visualLineNo(cm.doc, from)
|
|
121
|
+
to = visualLineEndNo(cm.doc, to)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let different = from != display.viewFrom || to != display.viewTo ||
|
|
125
|
+
display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth
|
|
126
|
+
adjustView(cm, from, to)
|
|
127
|
+
|
|
128
|
+
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom))
|
|
129
|
+
// Position the mover div to align with the current scroll position
|
|
130
|
+
cm.display.mover.style.top = display.viewOffset + "px"
|
|
131
|
+
|
|
132
|
+
let toUpdate = countDirtyView(cm)
|
|
133
|
+
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
|
|
134
|
+
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
|
|
135
|
+
return false
|
|
136
|
+
|
|
137
|
+
// For big changes, we hide the enclosing element during the
|
|
138
|
+
// update, since that speeds up the operations on most browsers.
|
|
139
|
+
let selSnapshot = selectionSnapshot(cm)
|
|
140
|
+
if (toUpdate > 4) display.lineDiv.style.display = "none"
|
|
141
|
+
patchDisplay(cm, display.updateLineNumbers, update.dims)
|
|
142
|
+
if (toUpdate > 4) display.lineDiv.style.display = ""
|
|
143
|
+
display.renderedView = display.view
|
|
144
|
+
// There might have been a widget with a focused element that got
|
|
145
|
+
// hidden or updated, if so re-focus it.
|
|
146
|
+
restoreSelection(selSnapshot)
|
|
147
|
+
|
|
148
|
+
// Prevent selection and cursors from interfering with the scroll
|
|
149
|
+
// width and height.
|
|
150
|
+
removeChildren(display.cursorDiv)
|
|
151
|
+
removeChildren(display.selectionDiv)
|
|
152
|
+
display.gutters.style.height = display.sizer.style.minHeight = 0
|
|
153
|
+
|
|
154
|
+
if (different) {
|
|
155
|
+
display.lastWrapHeight = update.wrapperHeight
|
|
156
|
+
display.lastWrapWidth = update.wrapperWidth
|
|
157
|
+
startWorker(cm, 400)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
display.updateLineNumbers = null
|
|
161
|
+
|
|
162
|
+
return true
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function postUpdateDisplay(cm, update) {
|
|
166
|
+
let viewport = update.viewport
|
|
167
|
+
|
|
168
|
+
for (let first = true;; first = false) {
|
|
169
|
+
if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
|
|
170
|
+
// Clip forced viewport to actual scrollable area.
|
|
171
|
+
if (viewport && viewport.top != null)
|
|
172
|
+
viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}
|
|
173
|
+
// Updated line heights might result in the drawn area not
|
|
174
|
+
// actually covering the viewport. Keep looping until it does.
|
|
175
|
+
update.visible = visibleLines(cm.display, cm.doc, viewport)
|
|
176
|
+
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
|
|
177
|
+
break
|
|
178
|
+
} else if (first) {
|
|
179
|
+
update.visible = visibleLines(cm.display, cm.doc, viewport)
|
|
180
|
+
}
|
|
181
|
+
if (!updateDisplayIfNeeded(cm, update)) break
|
|
182
|
+
updateHeightsInViewport(cm)
|
|
183
|
+
let barMeasure = measureForScrollbars(cm)
|
|
184
|
+
updateSelection(cm)
|
|
185
|
+
updateScrollbars(cm, barMeasure)
|
|
186
|
+
setDocumentHeight(cm, barMeasure)
|
|
187
|
+
update.force = false
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
update.signal(cm, "update", cm)
|
|
191
|
+
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
|
|
192
|
+
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo)
|
|
193
|
+
cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function updateDisplaySimple(cm, viewport) {
|
|
198
|
+
let update = new DisplayUpdate(cm, viewport)
|
|
199
|
+
if (updateDisplayIfNeeded(cm, update)) {
|
|
200
|
+
updateHeightsInViewport(cm)
|
|
201
|
+
postUpdateDisplay(cm, update)
|
|
202
|
+
let barMeasure = measureForScrollbars(cm)
|
|
203
|
+
updateSelection(cm)
|
|
204
|
+
updateScrollbars(cm, barMeasure)
|
|
205
|
+
setDocumentHeight(cm, barMeasure)
|
|
206
|
+
update.finish()
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Sync the actual display DOM structure with display.view, removing
|
|
211
|
+
// nodes for lines that are no longer in view, and creating the ones
|
|
212
|
+
// that are not there yet, and updating the ones that are out of
|
|
213
|
+
// date.
|
|
214
|
+
function patchDisplay(cm, updateNumbersFrom, dims) {
|
|
215
|
+
let display = cm.display, lineNumbers = cm.options.lineNumbers
|
|
216
|
+
let container = display.lineDiv, cur = container.firstChild
|
|
217
|
+
|
|
218
|
+
function rm(node) {
|
|
219
|
+
let next = node.nextSibling
|
|
220
|
+
// Works around a throw-scroll bug in OS X Webkit
|
|
221
|
+
if (webkit && mac && cm.display.currentWheelTarget == node)
|
|
222
|
+
node.style.display = "none"
|
|
223
|
+
else
|
|
224
|
+
node.parentNode.removeChild(node)
|
|
225
|
+
return next
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let view = display.view, lineN = display.viewFrom
|
|
229
|
+
// Loop over the elements in the view, syncing cur (the DOM nodes
|
|
230
|
+
// in display.lineDiv) with the view as we go.
|
|
231
|
+
for (let i = 0; i < view.length; i++) {
|
|
232
|
+
let lineView = view[i]
|
|
233
|
+
if (lineView.hidden) {
|
|
234
|
+
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
|
|
235
|
+
let node = buildLineElement(cm, lineView, lineN, dims)
|
|
236
|
+
container.insertBefore(node, cur)
|
|
237
|
+
} else { // Already drawn
|
|
238
|
+
while (cur != lineView.node) cur = rm(cur)
|
|
239
|
+
let updateNumber = lineNumbers && updateNumbersFrom != null &&
|
|
240
|
+
updateNumbersFrom <= lineN && lineView.lineNumber
|
|
241
|
+
if (lineView.changes) {
|
|
242
|
+
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false
|
|
243
|
+
updateLineForChanges(cm, lineView, lineN, dims)
|
|
244
|
+
}
|
|
245
|
+
if (updateNumber) {
|
|
246
|
+
removeChildren(lineView.lineNumber)
|
|
247
|
+
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
|
|
248
|
+
}
|
|
249
|
+
cur = lineView.node.nextSibling
|
|
250
|
+
}
|
|
251
|
+
lineN += lineView.size
|
|
252
|
+
}
|
|
253
|
+
while (cur) cur = rm(cur)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function updateGutterSpace(display) {
|
|
257
|
+
let width = display.gutters.offsetWidth
|
|
258
|
+
display.sizer.style.marginLeft = width + "px"
|
|
259
|
+
// Send an event to consumers responding to changes in gutter width.
|
|
260
|
+
signalLater(display, "gutterChanged", display)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function setDocumentHeight(cm, measure) {
|
|
264
|
+
cm.display.sizer.style.minHeight = measure.docHeight + "px"
|
|
265
|
+
cm.display.heightForcer.style.top = measure.docHeight + "px"
|
|
266
|
+
cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"
|
|
267
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { buildLineContent } from "../line/line_data.js"
|
|
2
|
+
import { lineNumberFor } from "../line/utils_line.js"
|
|
3
|
+
import { ie, ie_version } from "../util/browser.js"
|
|
4
|
+
import { elt, classTest } from "../util/dom.js"
|
|
5
|
+
import { signalLater } from "../util/operation_group.js"
|
|
6
|
+
|
|
7
|
+
// When an aspect of a line changes, a string is added to
|
|
8
|
+
// lineView.changes. This updates the relevant part of the line's
|
|
9
|
+
// DOM structure.
|
|
10
|
+
export function updateLineForChanges(cm, lineView, lineN, dims) {
|
|
11
|
+
for (let j = 0; j < lineView.changes.length; j++) {
|
|
12
|
+
let type = lineView.changes[j]
|
|
13
|
+
if (type == "text") updateLineText(cm, lineView)
|
|
14
|
+
else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims)
|
|
15
|
+
else if (type == "class") updateLineClasses(cm, lineView)
|
|
16
|
+
else if (type == "widget") updateLineWidgets(cm, lineView, dims)
|
|
17
|
+
}
|
|
18
|
+
lineView.changes = null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Lines with gutter elements, widgets or a background class need to
|
|
22
|
+
// be wrapped, and have the extra elements added to the wrapper div
|
|
23
|
+
function ensureLineWrapped(lineView) {
|
|
24
|
+
if (lineView.node == lineView.text) {
|
|
25
|
+
lineView.node = elt("div", null, null, "position: relative")
|
|
26
|
+
if (lineView.text.parentNode)
|
|
27
|
+
lineView.text.parentNode.replaceChild(lineView.node, lineView.text)
|
|
28
|
+
lineView.node.appendChild(lineView.text)
|
|
29
|
+
if (ie && ie_version < 8) lineView.node.style.zIndex = 2
|
|
30
|
+
}
|
|
31
|
+
return lineView.node
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function updateLineBackground(cm, lineView) {
|
|
35
|
+
let cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass
|
|
36
|
+
if (cls) cls += " CodeMirror-linebackground"
|
|
37
|
+
if (lineView.background) {
|
|
38
|
+
if (cls) lineView.background.className = cls
|
|
39
|
+
else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null }
|
|
40
|
+
} else if (cls) {
|
|
41
|
+
let wrap = ensureLineWrapped(lineView)
|
|
42
|
+
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild)
|
|
43
|
+
cm.display.input.setUneditable(lineView.background)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Wrapper around buildLineContent which will reuse the structure
|
|
48
|
+
// in display.externalMeasured when possible.
|
|
49
|
+
function getLineContent(cm, lineView) {
|
|
50
|
+
let ext = cm.display.externalMeasured
|
|
51
|
+
if (ext && ext.line == lineView.line) {
|
|
52
|
+
cm.display.externalMeasured = null
|
|
53
|
+
lineView.measure = ext.measure
|
|
54
|
+
return ext.built
|
|
55
|
+
}
|
|
56
|
+
return buildLineContent(cm, lineView)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Redraw the line's text. Interacts with the background and text
|
|
60
|
+
// classes because the mode may output tokens that influence these
|
|
61
|
+
// classes.
|
|
62
|
+
function updateLineText(cm, lineView) {
|
|
63
|
+
let cls = lineView.text.className
|
|
64
|
+
let built = getLineContent(cm, lineView)
|
|
65
|
+
if (lineView.text == lineView.node) lineView.node = built.pre
|
|
66
|
+
lineView.text.parentNode.replaceChild(built.pre, lineView.text)
|
|
67
|
+
lineView.text = built.pre
|
|
68
|
+
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
|
|
69
|
+
lineView.bgClass = built.bgClass
|
|
70
|
+
lineView.textClass = built.textClass
|
|
71
|
+
updateLineClasses(cm, lineView)
|
|
72
|
+
} else if (cls) {
|
|
73
|
+
lineView.text.className = cls
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function updateLineClasses(cm, lineView) {
|
|
78
|
+
updateLineBackground(cm, lineView)
|
|
79
|
+
if (lineView.line.wrapClass)
|
|
80
|
+
ensureLineWrapped(lineView).className = lineView.line.wrapClass
|
|
81
|
+
else if (lineView.node != lineView.text)
|
|
82
|
+
lineView.node.className = ""
|
|
83
|
+
let textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass
|
|
84
|
+
lineView.text.className = textClass || ""
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function updateLineGutter(cm, lineView, lineN, dims) {
|
|
88
|
+
if (lineView.gutter) {
|
|
89
|
+
lineView.node.removeChild(lineView.gutter)
|
|
90
|
+
lineView.gutter = null
|
|
91
|
+
}
|
|
92
|
+
if (lineView.gutterBackground) {
|
|
93
|
+
lineView.node.removeChild(lineView.gutterBackground)
|
|
94
|
+
lineView.gutterBackground = null
|
|
95
|
+
}
|
|
96
|
+
if (lineView.line.gutterClass) {
|
|
97
|
+
let wrap = ensureLineWrapped(lineView)
|
|
98
|
+
lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
|
|
99
|
+
`left: ${cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth}px; width: ${dims.gutterTotalWidth}px`)
|
|
100
|
+
cm.display.input.setUneditable(lineView.gutterBackground)
|
|
101
|
+
wrap.insertBefore(lineView.gutterBackground, lineView.text)
|
|
102
|
+
}
|
|
103
|
+
let markers = lineView.line.gutterMarkers
|
|
104
|
+
if (cm.options.lineNumbers || markers) {
|
|
105
|
+
let wrap = ensureLineWrapped(lineView)
|
|
106
|
+
let gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", `left: ${cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth}px`)
|
|
107
|
+
gutterWrap.setAttribute("aria-hidden", "true")
|
|
108
|
+
cm.display.input.setUneditable(gutterWrap)
|
|
109
|
+
wrap.insertBefore(gutterWrap, lineView.text)
|
|
110
|
+
if (lineView.line.gutterClass)
|
|
111
|
+
gutterWrap.className += " " + lineView.line.gutterClass
|
|
112
|
+
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
|
|
113
|
+
lineView.lineNumber = gutterWrap.appendChild(
|
|
114
|
+
elt("div", lineNumberFor(cm.options, lineN),
|
|
115
|
+
"CodeMirror-linenumber CodeMirror-gutter-elt",
|
|
116
|
+
`left: ${dims.gutterLeft["CodeMirror-linenumbers"]}px; width: ${cm.display.lineNumInnerWidth}px`))
|
|
117
|
+
if (markers) for (let k = 0; k < cm.display.gutterSpecs.length; ++k) {
|
|
118
|
+
let id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id]
|
|
119
|
+
if (found)
|
|
120
|
+
gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
|
|
121
|
+
`left: ${dims.gutterLeft[id]}px; width: ${dims.gutterWidth[id]}px`))
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function updateLineWidgets(cm, lineView, dims) {
|
|
127
|
+
if (lineView.alignable) lineView.alignable = null
|
|
128
|
+
let isWidget = classTest("CodeMirror-linewidget")
|
|
129
|
+
for (let node = lineView.node.firstChild, next; node; node = next) {
|
|
130
|
+
next = node.nextSibling
|
|
131
|
+
if (isWidget.test(node.className)) lineView.node.removeChild(node)
|
|
132
|
+
}
|
|
133
|
+
insertLineWidgets(cm, lineView, dims)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Build a line's DOM representation from scratch
|
|
137
|
+
export function buildLineElement(cm, lineView, lineN, dims) {
|
|
138
|
+
let built = getLineContent(cm, lineView)
|
|
139
|
+
lineView.text = lineView.node = built.pre
|
|
140
|
+
if (built.bgClass) lineView.bgClass = built.bgClass
|
|
141
|
+
if (built.textClass) lineView.textClass = built.textClass
|
|
142
|
+
|
|
143
|
+
updateLineClasses(cm, lineView)
|
|
144
|
+
updateLineGutter(cm, lineView, lineN, dims)
|
|
145
|
+
insertLineWidgets(cm, lineView, dims)
|
|
146
|
+
return lineView.node
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// A lineView may contain multiple logical lines (when merged by
|
|
150
|
+
// collapsed spans). The widgets for all of them need to be drawn.
|
|
151
|
+
function insertLineWidgets(cm, lineView, dims) {
|
|
152
|
+
insertLineWidgetsFor(cm, lineView.line, lineView, dims, true)
|
|
153
|
+
if (lineView.rest) for (let i = 0; i < lineView.rest.length; i++)
|
|
154
|
+
insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
|
|
158
|
+
if (!line.widgets) return
|
|
159
|
+
let wrap = ensureLineWrapped(lineView)
|
|
160
|
+
for (let i = 0, ws = line.widgets; i < ws.length; ++i) {
|
|
161
|
+
let widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""))
|
|
162
|
+
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true")
|
|
163
|
+
positionLineWidget(widget, node, lineView, dims)
|
|
164
|
+
cm.display.input.setUneditable(node)
|
|
165
|
+
if (allowAbove && widget.above)
|
|
166
|
+
wrap.insertBefore(node, lineView.gutter || lineView.text)
|
|
167
|
+
else
|
|
168
|
+
wrap.appendChild(node)
|
|
169
|
+
signalLater(widget, "redraw")
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function positionLineWidget(widget, node, lineView, dims) {
|
|
174
|
+
if (widget.noHScroll) {
|
|
175
|
+
;(lineView.alignable || (lineView.alignable = [])).push(node)
|
|
176
|
+
let width = dims.wrapperWidth
|
|
177
|
+
node.style.left = dims.fixedPos + "px"
|
|
178
|
+
if (!widget.coverGutter) {
|
|
179
|
+
width -= dims.gutterTotalWidth
|
|
180
|
+
node.style.paddingLeft = dims.gutterTotalWidth + "px"
|
|
181
|
+
}
|
|
182
|
+
node.style.width = width + "px"
|
|
183
|
+
}
|
|
184
|
+
if (widget.coverGutter) {
|
|
185
|
+
node.style.zIndex = 5
|
|
186
|
+
node.style.position = "relative"
|
|
187
|
+
if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { heightAtLine } from "../line/spans.js"
|
|
2
|
+
import { getLine, lineAtHeight, updateLineHeight } from "../line/utils_line.js"
|
|
3
|
+
import { paddingTop, charWidth } from "../measurement/position_measurement.js"
|
|
4
|
+
import { ie, ie_version } from "../util/browser.js"
|
|
5
|
+
|
|
6
|
+
// Read the actual heights of the rendered lines, and update their
|
|
7
|
+
// stored heights to match.
|
|
8
|
+
export function updateHeightsInViewport(cm) {
|
|
9
|
+
let display = cm.display
|
|
10
|
+
let prevBottom = display.lineDiv.offsetTop
|
|
11
|
+
let viewTop = Math.max(0, display.scroller.getBoundingClientRect().top)
|
|
12
|
+
let oldHeight = display.lineDiv.getBoundingClientRect().top
|
|
13
|
+
let mustScroll = 0
|
|
14
|
+
for (let i = 0; i < display.view.length; i++) {
|
|
15
|
+
let cur = display.view[i], wrapping = cm.options.lineWrapping
|
|
16
|
+
let height, width = 0
|
|
17
|
+
if (cur.hidden) continue
|
|
18
|
+
oldHeight += cur.line.height
|
|
19
|
+
if (ie && ie_version < 8) {
|
|
20
|
+
let bot = cur.node.offsetTop + cur.node.offsetHeight
|
|
21
|
+
height = bot - prevBottom
|
|
22
|
+
prevBottom = bot
|
|
23
|
+
} else {
|
|
24
|
+
let box = cur.node.getBoundingClientRect()
|
|
25
|
+
height = box.bottom - box.top
|
|
26
|
+
// Check that lines don't extend past the right of the current
|
|
27
|
+
// editor width
|
|
28
|
+
if (!wrapping && cur.text.firstChild)
|
|
29
|
+
width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1
|
|
30
|
+
}
|
|
31
|
+
let diff = cur.line.height - height
|
|
32
|
+
if (diff > .005 || diff < -.005) {
|
|
33
|
+
if (oldHeight < viewTop) mustScroll -= diff
|
|
34
|
+
updateLineHeight(cur.line, height)
|
|
35
|
+
updateWidgetHeight(cur.line)
|
|
36
|
+
if (cur.rest) for (let j = 0; j < cur.rest.length; j++)
|
|
37
|
+
updateWidgetHeight(cur.rest[j])
|
|
38
|
+
}
|
|
39
|
+
if (width > cm.display.sizerWidth) {
|
|
40
|
+
let chWidth = Math.ceil(width / charWidth(cm.display))
|
|
41
|
+
if (chWidth > cm.display.maxLineLength) {
|
|
42
|
+
cm.display.maxLineLength = chWidth
|
|
43
|
+
cm.display.maxLine = cur.line
|
|
44
|
+
cm.display.maxLineChanged = true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (Math.abs(mustScroll) > 2) display.scroller.scrollTop += mustScroll
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Read and store the height of line widgets associated with the
|
|
52
|
+
// given line.
|
|
53
|
+
function updateWidgetHeight(line) {
|
|
54
|
+
if (line.widgets) for (let i = 0; i < line.widgets.length; ++i) {
|
|
55
|
+
let w = line.widgets[i], parent = w.node.parentNode
|
|
56
|
+
if (parent) w.height = parent.offsetHeight
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Compute the lines that are visible in a given viewport (defaults
|
|
61
|
+
// the the current scroll position). viewport may contain top,
|
|
62
|
+
// height, and ensure (see op.scrollToPos) properties.
|
|
63
|
+
export function visibleLines(display, doc, viewport) {
|
|
64
|
+
let top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop
|
|
65
|
+
top = Math.floor(top - paddingTop(display))
|
|
66
|
+
let bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight
|
|
67
|
+
|
|
68
|
+
let from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom)
|
|
69
|
+
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
|
|
70
|
+
// forces those lines into the viewport (if possible).
|
|
71
|
+
if (viewport && viewport.ensure) {
|
|
72
|
+
let ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line
|
|
73
|
+
if (ensureFrom < from) {
|
|
74
|
+
from = ensureFrom
|
|
75
|
+
to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)
|
|
76
|
+
} else if (Math.min(ensureTo, doc.lastLine()) >= to) {
|
|
77
|
+
from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight)
|
|
78
|
+
to = ensureTo
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {from: from, to: Math.max(to, from + 1)}
|
|
82
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { buildViewArray } from "../line/line_data.js"
|
|
2
|
+
import { sawCollapsedSpans } from "../line/saw_special_spans.js"
|
|
3
|
+
import { visualLineEndNo, visualLineNo } from "../line/spans.js"
|
|
4
|
+
import { findViewIndex } from "../measurement/position_measurement.js"
|
|
5
|
+
import { indexOf } from "../util/misc.js"
|
|
6
|
+
|
|
7
|
+
// Updates the display.view data structure for a given change to the
|
|
8
|
+
// document. From and to are in pre-change coordinates. Lendiff is
|
|
9
|
+
// the amount of lines added or subtracted by the change. This is
|
|
10
|
+
// used for changes that span multiple lines, or change the way
|
|
11
|
+
// lines are divided into visual lines. regLineChange (below)
|
|
12
|
+
// registers single-line changes.
|
|
13
|
+
export function regChange(cm, from, to, lendiff) {
|
|
14
|
+
if (from == null) from = cm.doc.first
|
|
15
|
+
if (to == null) to = cm.doc.first + cm.doc.size
|
|
16
|
+
if (!lendiff) lendiff = 0
|
|
17
|
+
|
|
18
|
+
let display = cm.display
|
|
19
|
+
if (lendiff && to < display.viewTo &&
|
|
20
|
+
(display.updateLineNumbers == null || display.updateLineNumbers > from))
|
|
21
|
+
display.updateLineNumbers = from
|
|
22
|
+
|
|
23
|
+
cm.curOp.viewChanged = true
|
|
24
|
+
|
|
25
|
+
if (from >= display.viewTo) { // Change after
|
|
26
|
+
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
|
|
27
|
+
resetView(cm)
|
|
28
|
+
} else if (to <= display.viewFrom) { // Change before
|
|
29
|
+
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
|
|
30
|
+
resetView(cm)
|
|
31
|
+
} else {
|
|
32
|
+
display.viewFrom += lendiff
|
|
33
|
+
display.viewTo += lendiff
|
|
34
|
+
}
|
|
35
|
+
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
|
|
36
|
+
resetView(cm)
|
|
37
|
+
} else if (from <= display.viewFrom) { // Top overlap
|
|
38
|
+
let cut = viewCuttingPoint(cm, to, to + lendiff, 1)
|
|
39
|
+
if (cut) {
|
|
40
|
+
display.view = display.view.slice(cut.index)
|
|
41
|
+
display.viewFrom = cut.lineN
|
|
42
|
+
display.viewTo += lendiff
|
|
43
|
+
} else {
|
|
44
|
+
resetView(cm)
|
|
45
|
+
}
|
|
46
|
+
} else if (to >= display.viewTo) { // Bottom overlap
|
|
47
|
+
let cut = viewCuttingPoint(cm, from, from, -1)
|
|
48
|
+
if (cut) {
|
|
49
|
+
display.view = display.view.slice(0, cut.index)
|
|
50
|
+
display.viewTo = cut.lineN
|
|
51
|
+
} else {
|
|
52
|
+
resetView(cm)
|
|
53
|
+
}
|
|
54
|
+
} else { // Gap in the middle
|
|
55
|
+
let cutTop = viewCuttingPoint(cm, from, from, -1)
|
|
56
|
+
let cutBot = viewCuttingPoint(cm, to, to + lendiff, 1)
|
|
57
|
+
if (cutTop && cutBot) {
|
|
58
|
+
display.view = display.view.slice(0, cutTop.index)
|
|
59
|
+
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
|
|
60
|
+
.concat(display.view.slice(cutBot.index))
|
|
61
|
+
display.viewTo += lendiff
|
|
62
|
+
} else {
|
|
63
|
+
resetView(cm)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let ext = display.externalMeasured
|
|
68
|
+
if (ext) {
|
|
69
|
+
if (to < ext.lineN)
|
|
70
|
+
ext.lineN += lendiff
|
|
71
|
+
else if (from < ext.lineN + ext.size)
|
|
72
|
+
display.externalMeasured = null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Register a change to a single line. Type must be one of "text",
|
|
77
|
+
// "gutter", "class", "widget"
|
|
78
|
+
export function regLineChange(cm, line, type) {
|
|
79
|
+
cm.curOp.viewChanged = true
|
|
80
|
+
let display = cm.display, ext = cm.display.externalMeasured
|
|
81
|
+
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
|
|
82
|
+
display.externalMeasured = null
|
|
83
|
+
|
|
84
|
+
if (line < display.viewFrom || line >= display.viewTo) return
|
|
85
|
+
let lineView = display.view[findViewIndex(cm, line)]
|
|
86
|
+
if (lineView.node == null) return
|
|
87
|
+
let arr = lineView.changes || (lineView.changes = [])
|
|
88
|
+
if (indexOf(arr, type) == -1) arr.push(type)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Clear the view.
|
|
92
|
+
export function resetView(cm) {
|
|
93
|
+
cm.display.viewFrom = cm.display.viewTo = cm.doc.first
|
|
94
|
+
cm.display.view = []
|
|
95
|
+
cm.display.viewOffset = 0
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function viewCuttingPoint(cm, oldN, newN, dir) {
|
|
99
|
+
let index = findViewIndex(cm, oldN), diff, view = cm.display.view
|
|
100
|
+
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
|
|
101
|
+
return {index: index, lineN: newN}
|
|
102
|
+
let n = cm.display.viewFrom
|
|
103
|
+
for (let i = 0; i < index; i++)
|
|
104
|
+
n += view[i].size
|
|
105
|
+
if (n != oldN) {
|
|
106
|
+
if (dir > 0) {
|
|
107
|
+
if (index == view.length - 1) return null
|
|
108
|
+
diff = (n + view[index].size) - oldN
|
|
109
|
+
index++
|
|
110
|
+
} else {
|
|
111
|
+
diff = n - oldN
|
|
112
|
+
}
|
|
113
|
+
oldN += diff; newN += diff
|
|
114
|
+
}
|
|
115
|
+
while (visualLineNo(cm.doc, newN) != newN) {
|
|
116
|
+
if (index == (dir < 0 ? 0 : view.length - 1)) return null
|
|
117
|
+
newN += dir * view[index - (dir < 0 ? 1 : 0)].size
|
|
118
|
+
index += dir
|
|
119
|
+
}
|
|
120
|
+
return {index: index, lineN: newN}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Force the view to cover a given range, adding empty view element
|
|
124
|
+
// or clipping off existing ones as needed.
|
|
125
|
+
export function adjustView(cm, from, to) {
|
|
126
|
+
let display = cm.display, view = display.view
|
|
127
|
+
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
|
|
128
|
+
display.view = buildViewArray(cm, from, to)
|
|
129
|
+
display.viewFrom = from
|
|
130
|
+
} else {
|
|
131
|
+
if (display.viewFrom > from)
|
|
132
|
+
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view)
|
|
133
|
+
else if (display.viewFrom < from)
|
|
134
|
+
display.view = display.view.slice(findViewIndex(cm, from))
|
|
135
|
+
display.viewFrom = from
|
|
136
|
+
if (display.viewTo < to)
|
|
137
|
+
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to))
|
|
138
|
+
else if (display.viewTo > to)
|
|
139
|
+
display.view = display.view.slice(0, findViewIndex(cm, to))
|
|
140
|
+
}
|
|
141
|
+
display.viewTo = to
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Count the number of lines in the view whose DOM representation is
|
|
145
|
+
// out of date (or nonexistent).
|
|
146
|
+
export function countDirtyView(cm) {
|
|
147
|
+
let view = cm.display.view, dirty = 0
|
|
148
|
+
for (let i = 0; i < view.length; i++) {
|
|
149
|
+
let lineView = view[i]
|
|
150
|
+
if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty
|
|
151
|
+
}
|
|
152
|
+
return dirty
|
|
153
|
+
}
|