@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,194 @@
|
|
|
1
|
+
import { addClass, elt, rmClass } from "../util/dom.js"
|
|
2
|
+
import { on } from "../util/event.js"
|
|
3
|
+
import { scrollGap, paddingVert } from "../measurement/position_measurement.js"
|
|
4
|
+
import { ie, ie_version, mac, mac_geMountainLion } from "../util/browser.js"
|
|
5
|
+
import { updateHeightsInViewport } from "./update_lines.js"
|
|
6
|
+
import { Delayed } from "../util/misc.js"
|
|
7
|
+
|
|
8
|
+
import { setScrollLeft, updateScrollTop } from "./scrolling.js"
|
|
9
|
+
|
|
10
|
+
// SCROLLBARS
|
|
11
|
+
|
|
12
|
+
// Prepare DOM reads needed to update the scrollbars. Done in one
|
|
13
|
+
// shot to minimize update/measure roundtrips.
|
|
14
|
+
export function measureForScrollbars(cm) {
|
|
15
|
+
let d = cm.display, gutterW = d.gutters.offsetWidth
|
|
16
|
+
let docH = Math.round(cm.doc.height + paddingVert(cm.display))
|
|
17
|
+
return {
|
|
18
|
+
clientHeight: d.scroller.clientHeight,
|
|
19
|
+
viewHeight: d.wrapper.clientHeight,
|
|
20
|
+
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
|
|
21
|
+
viewWidth: d.wrapper.clientWidth,
|
|
22
|
+
barLeft: cm.options.fixedGutter ? gutterW : 0,
|
|
23
|
+
docHeight: docH,
|
|
24
|
+
scrollHeight: docH + scrollGap(cm) + d.barHeight,
|
|
25
|
+
nativeBarWidth: d.nativeBarWidth,
|
|
26
|
+
gutterWidth: gutterW
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class NativeScrollbars {
|
|
31
|
+
constructor(place, scroll, cm) {
|
|
32
|
+
this.cm = cm
|
|
33
|
+
let vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
|
|
34
|
+
let horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
|
|
35
|
+
vert.tabIndex = horiz.tabIndex = -1
|
|
36
|
+
place(vert); place(horiz)
|
|
37
|
+
|
|
38
|
+
on(vert, "scroll", () => {
|
|
39
|
+
if (vert.clientHeight) scroll(vert.scrollTop, "vertical")
|
|
40
|
+
})
|
|
41
|
+
on(horiz, "scroll", () => {
|
|
42
|
+
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal")
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
this.checkedZeroWidth = false
|
|
46
|
+
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
|
|
47
|
+
if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
update(measure) {
|
|
51
|
+
let needsH = measure.scrollWidth > measure.clientWidth + 1
|
|
52
|
+
let needsV = measure.scrollHeight > measure.clientHeight + 1
|
|
53
|
+
let sWidth = measure.nativeBarWidth
|
|
54
|
+
|
|
55
|
+
if (needsV) {
|
|
56
|
+
this.vert.style.display = "block"
|
|
57
|
+
this.vert.style.bottom = needsH ? sWidth + "px" : "0"
|
|
58
|
+
let totalHeight = measure.viewHeight - (needsH ? sWidth : 0)
|
|
59
|
+
// A bug in IE8 can cause this value to be negative, so guard it.
|
|
60
|
+
this.vert.firstChild.style.height =
|
|
61
|
+
Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"
|
|
62
|
+
} else {
|
|
63
|
+
this.vert.scrollTop = 0
|
|
64
|
+
this.vert.style.display = ""
|
|
65
|
+
this.vert.firstChild.style.height = "0"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (needsH) {
|
|
69
|
+
this.horiz.style.display = "block"
|
|
70
|
+
this.horiz.style.right = needsV ? sWidth + "px" : "0"
|
|
71
|
+
this.horiz.style.left = measure.barLeft + "px"
|
|
72
|
+
let totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0)
|
|
73
|
+
this.horiz.firstChild.style.width =
|
|
74
|
+
Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px"
|
|
75
|
+
} else {
|
|
76
|
+
this.horiz.style.display = ""
|
|
77
|
+
this.horiz.firstChild.style.width = "0"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!this.checkedZeroWidth && measure.clientHeight > 0) {
|
|
81
|
+
if (sWidth == 0) this.zeroWidthHack()
|
|
82
|
+
this.checkedZeroWidth = true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setScrollLeft(pos) {
|
|
89
|
+
if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos
|
|
90
|
+
if (this.disableHoriz) this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setScrollTop(pos) {
|
|
94
|
+
if (this.vert.scrollTop != pos) this.vert.scrollTop = pos
|
|
95
|
+
if (this.disableVert) this.enableZeroWidthBar(this.vert, this.disableVert, "vert")
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
zeroWidthHack() {
|
|
99
|
+
let w = mac && !mac_geMountainLion ? "12px" : "18px"
|
|
100
|
+
this.horiz.style.height = this.vert.style.width = w
|
|
101
|
+
this.horiz.style.visibility = this.vert.style.visibility = "hidden"
|
|
102
|
+
this.disableHoriz = new Delayed
|
|
103
|
+
this.disableVert = new Delayed
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
enableZeroWidthBar(bar, delay, type) {
|
|
107
|
+
bar.style.visibility = ""
|
|
108
|
+
function maybeDisable() {
|
|
109
|
+
// To find out whether the scrollbar is still visible, we
|
|
110
|
+
// check whether the element under the pixel in the bottom
|
|
111
|
+
// right corner of the scrollbar box is the scrollbar box
|
|
112
|
+
// itself (when the bar is still visible) or its filler child
|
|
113
|
+
// (when the bar is hidden). If it is still visible, we keep
|
|
114
|
+
// it enabled, if it's hidden, we disable pointer events.
|
|
115
|
+
let box = bar.getBoundingClientRect()
|
|
116
|
+
let elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
|
|
117
|
+
: document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1)
|
|
118
|
+
if (elt != bar) bar.style.visibility = "hidden"
|
|
119
|
+
else delay.set(1000, maybeDisable)
|
|
120
|
+
}
|
|
121
|
+
delay.set(1000, maybeDisable)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
clear() {
|
|
125
|
+
let parent = this.horiz.parentNode
|
|
126
|
+
parent.removeChild(this.horiz)
|
|
127
|
+
parent.removeChild(this.vert)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class NullScrollbars {
|
|
132
|
+
update() { return {bottom: 0, right: 0} }
|
|
133
|
+
setScrollLeft() {}
|
|
134
|
+
setScrollTop() {}
|
|
135
|
+
clear() {}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function updateScrollbars(cm, measure) {
|
|
139
|
+
if (!measure) measure = measureForScrollbars(cm)
|
|
140
|
+
let startWidth = cm.display.barWidth, startHeight = cm.display.barHeight
|
|
141
|
+
updateScrollbarsInner(cm, measure)
|
|
142
|
+
for (let i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
|
|
143
|
+
if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
|
|
144
|
+
updateHeightsInViewport(cm)
|
|
145
|
+
updateScrollbarsInner(cm, measureForScrollbars(cm))
|
|
146
|
+
startWidth = cm.display.barWidth; startHeight = cm.display.barHeight
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Re-synchronize the fake scrollbars with the actual size of the
|
|
151
|
+
// content.
|
|
152
|
+
function updateScrollbarsInner(cm, measure) {
|
|
153
|
+
let d = cm.display
|
|
154
|
+
let sizes = d.scrollbars.update(measure)
|
|
155
|
+
|
|
156
|
+
d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"
|
|
157
|
+
d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"
|
|
158
|
+
d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
|
|
159
|
+
|
|
160
|
+
if (sizes.right && sizes.bottom) {
|
|
161
|
+
d.scrollbarFiller.style.display = "block"
|
|
162
|
+
d.scrollbarFiller.style.height = sizes.bottom + "px"
|
|
163
|
+
d.scrollbarFiller.style.width = sizes.right + "px"
|
|
164
|
+
} else d.scrollbarFiller.style.display = ""
|
|
165
|
+
if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
|
|
166
|
+
d.gutterFiller.style.display = "block"
|
|
167
|
+
d.gutterFiller.style.height = sizes.bottom + "px"
|
|
168
|
+
d.gutterFiller.style.width = measure.gutterWidth + "px"
|
|
169
|
+
} else d.gutterFiller.style.display = ""
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export let scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}
|
|
173
|
+
|
|
174
|
+
export function initScrollbars(cm) {
|
|
175
|
+
if (cm.display.scrollbars) {
|
|
176
|
+
cm.display.scrollbars.clear()
|
|
177
|
+
if (cm.display.scrollbars.addClass)
|
|
178
|
+
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](node => {
|
|
182
|
+
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
|
|
183
|
+
// Prevent clicks in the scrollbars from killing focus
|
|
184
|
+
on(node, "mousedown", () => {
|
|
185
|
+
if (cm.state.focused) setTimeout(() => cm.display.input.focus(), 0)
|
|
186
|
+
})
|
|
187
|
+
node.setAttribute("cm-not-content", "true")
|
|
188
|
+
}, (pos, axis) => {
|
|
189
|
+
if (axis == "horizontal") setScrollLeft(cm, pos)
|
|
190
|
+
else updateScrollTop(cm, pos)
|
|
191
|
+
}, cm)
|
|
192
|
+
if (cm.display.scrollbars.addClass)
|
|
193
|
+
addClass(cm.display.wrapper, cm.display.scrollbars.addClass)
|
|
194
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Pos } from "../line/pos.js"
|
|
2
|
+
import { cursorCoords, displayHeight, displayWidth, estimateCoords, paddingTop, paddingVert, scrollGap, textHeight } from "../measurement/position_measurement.js"
|
|
3
|
+
import { gecko, phantom } from "../util/browser.js"
|
|
4
|
+
import { elt } from "../util/dom.js"
|
|
5
|
+
import { signalDOMEvent } from "../util/event.js"
|
|
6
|
+
|
|
7
|
+
import { startWorker } from "./highlight_worker.js"
|
|
8
|
+
import { alignHorizontally } from "./line_numbers.js"
|
|
9
|
+
import { updateDisplaySimple } from "./update_display.js"
|
|
10
|
+
|
|
11
|
+
// SCROLLING THINGS INTO VIEW
|
|
12
|
+
|
|
13
|
+
// If an editor sits on the top or bottom of the window, partially
|
|
14
|
+
// scrolled out of view, this ensures that the cursor is visible.
|
|
15
|
+
export function maybeScrollWindow(cm, rect) {
|
|
16
|
+
if (signalDOMEvent(cm, "scrollCursorIntoView")) return
|
|
17
|
+
|
|
18
|
+
let display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
|
|
19
|
+
let doc = display.wrapper.ownerDocument
|
|
20
|
+
if (rect.top + box.top < 0) doScroll = true
|
|
21
|
+
else if (rect.bottom + box.top > (doc.defaultView.innerHeight || doc.documentElement.clientHeight)) doScroll = false
|
|
22
|
+
if (doScroll != null && !phantom) {
|
|
23
|
+
let scrollNode = elt("div", "\u200b", null, `position: absolute;
|
|
24
|
+
top: ${rect.top - display.viewOffset - paddingTop(cm.display)}px;
|
|
25
|
+
height: ${rect.bottom - rect.top + scrollGap(cm) + display.barHeight}px;
|
|
26
|
+
left: ${rect.left}px; width: ${Math.max(2, rect.right - rect.left)}px;`)
|
|
27
|
+
cm.display.lineSpace.appendChild(scrollNode)
|
|
28
|
+
scrollNode.scrollIntoView(doScroll)
|
|
29
|
+
cm.display.lineSpace.removeChild(scrollNode)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Scroll a given position into view (immediately), verifying that
|
|
34
|
+
// it actually became visible (as line heights are accurately
|
|
35
|
+
// measured, the position of something may 'drift' during drawing).
|
|
36
|
+
export function scrollPosIntoView(cm, pos, end, margin) {
|
|
37
|
+
if (margin == null) margin = 0
|
|
38
|
+
let rect
|
|
39
|
+
if (!cm.options.lineWrapping && pos == end) {
|
|
40
|
+
// Set pos and end to the cursor positions around the character pos sticks to
|
|
41
|
+
// If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
|
|
42
|
+
// If pos == Pos(_, 0, "before"), pos and end are unchanged
|
|
43
|
+
end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos
|
|
44
|
+
pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos
|
|
45
|
+
}
|
|
46
|
+
for (let limit = 0; limit < 5; limit++) {
|
|
47
|
+
let changed = false
|
|
48
|
+
let coords = cursorCoords(cm, pos)
|
|
49
|
+
let endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
|
|
50
|
+
rect = {left: Math.min(coords.left, endCoords.left),
|
|
51
|
+
top: Math.min(coords.top, endCoords.top) - margin,
|
|
52
|
+
right: Math.max(coords.left, endCoords.left),
|
|
53
|
+
bottom: Math.max(coords.bottom, endCoords.bottom) + margin}
|
|
54
|
+
let scrollPos = calculateScrollPos(cm, rect)
|
|
55
|
+
let startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
|
|
56
|
+
if (scrollPos.scrollTop != null) {
|
|
57
|
+
updateScrollTop(cm, scrollPos.scrollTop)
|
|
58
|
+
if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true
|
|
59
|
+
}
|
|
60
|
+
if (scrollPos.scrollLeft != null) {
|
|
61
|
+
setScrollLeft(cm, scrollPos.scrollLeft)
|
|
62
|
+
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true
|
|
63
|
+
}
|
|
64
|
+
if (!changed) break
|
|
65
|
+
}
|
|
66
|
+
return rect
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Scroll a given set of coordinates into view (immediately).
|
|
70
|
+
export function scrollIntoView(cm, rect) {
|
|
71
|
+
let scrollPos = calculateScrollPos(cm, rect)
|
|
72
|
+
if (scrollPos.scrollTop != null) updateScrollTop(cm, scrollPos.scrollTop)
|
|
73
|
+
if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Calculate a new scroll position needed to scroll the given
|
|
77
|
+
// rectangle into view. Returns an object with scrollTop and
|
|
78
|
+
// scrollLeft properties. When these are undefined, the
|
|
79
|
+
// vertical/horizontal position does not need to be adjusted.
|
|
80
|
+
function calculateScrollPos(cm, rect) {
|
|
81
|
+
let display = cm.display, snapMargin = textHeight(cm.display)
|
|
82
|
+
if (rect.top < 0) rect.top = 0
|
|
83
|
+
let screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
|
|
84
|
+
let screen = displayHeight(cm), result = {}
|
|
85
|
+
if (rect.bottom - rect.top > screen) rect.bottom = rect.top + screen
|
|
86
|
+
let docBottom = cm.doc.height + paddingVert(display)
|
|
87
|
+
let atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin
|
|
88
|
+
if (rect.top < screentop) {
|
|
89
|
+
result.scrollTop = atTop ? 0 : rect.top
|
|
90
|
+
} else if (rect.bottom > screentop + screen) {
|
|
91
|
+
let newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen)
|
|
92
|
+
if (newTop != screentop) result.scrollTop = newTop
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let gutterSpace = cm.options.fixedGutter ? 0 : display.gutters.offsetWidth
|
|
96
|
+
let screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft - gutterSpace
|
|
97
|
+
let screenw = displayWidth(cm) - display.gutters.offsetWidth
|
|
98
|
+
let tooWide = rect.right - rect.left > screenw
|
|
99
|
+
if (tooWide) rect.right = rect.left + screenw
|
|
100
|
+
if (rect.left < 10)
|
|
101
|
+
result.scrollLeft = 0
|
|
102
|
+
else if (rect.left < screenleft)
|
|
103
|
+
result.scrollLeft = Math.max(0, rect.left + gutterSpace - (tooWide ? 0 : 10))
|
|
104
|
+
else if (rect.right > screenw + screenleft - 3)
|
|
105
|
+
result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw
|
|
106
|
+
return result
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Store a relative adjustment to the scroll position in the current
|
|
110
|
+
// operation (to be applied when the operation finishes).
|
|
111
|
+
export function addToScrollTop(cm, top) {
|
|
112
|
+
if (top == null) return
|
|
113
|
+
resolveScrollToPos(cm)
|
|
114
|
+
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Make sure that at the end of the operation the current cursor is
|
|
118
|
+
// shown.
|
|
119
|
+
export function ensureCursorVisible(cm) {
|
|
120
|
+
resolveScrollToPos(cm)
|
|
121
|
+
let cur = cm.getCursor()
|
|
122
|
+
cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function scrollToCoords(cm, x, y) {
|
|
126
|
+
if (x != null || y != null) resolveScrollToPos(cm)
|
|
127
|
+
if (x != null) cm.curOp.scrollLeft = x
|
|
128
|
+
if (y != null) cm.curOp.scrollTop = y
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function scrollToRange(cm, range) {
|
|
132
|
+
resolveScrollToPos(cm)
|
|
133
|
+
cm.curOp.scrollToPos = range
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// When an operation has its scrollToPos property set, and another
|
|
137
|
+
// scroll action is applied before the end of the operation, this
|
|
138
|
+
// 'simulates' scrolling that position into view in a cheap way, so
|
|
139
|
+
// that the effect of intermediate scroll commands is not ignored.
|
|
140
|
+
function resolveScrollToPos(cm) {
|
|
141
|
+
let range = cm.curOp.scrollToPos
|
|
142
|
+
if (range) {
|
|
143
|
+
cm.curOp.scrollToPos = null
|
|
144
|
+
let from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to)
|
|
145
|
+
scrollToCoordsRange(cm, from, to, range.margin)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function scrollToCoordsRange(cm, from, to, margin) {
|
|
150
|
+
let sPos = calculateScrollPos(cm, {
|
|
151
|
+
left: Math.min(from.left, to.left),
|
|
152
|
+
top: Math.min(from.top, to.top) - margin,
|
|
153
|
+
right: Math.max(from.right, to.right),
|
|
154
|
+
bottom: Math.max(from.bottom, to.bottom) + margin
|
|
155
|
+
})
|
|
156
|
+
scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Sync the scrollable area and scrollbars, ensure the viewport
|
|
160
|
+
// covers the visible area.
|
|
161
|
+
export function updateScrollTop(cm, val) {
|
|
162
|
+
if (Math.abs(cm.doc.scrollTop - val) < 2) return
|
|
163
|
+
if (!gecko) updateDisplaySimple(cm, {top: val})
|
|
164
|
+
setScrollTop(cm, val, true)
|
|
165
|
+
if (gecko) updateDisplaySimple(cm)
|
|
166
|
+
startWorker(cm, 100)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function setScrollTop(cm, val, forceScroll) {
|
|
170
|
+
val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val))
|
|
171
|
+
if (cm.display.scroller.scrollTop == val && !forceScroll) return
|
|
172
|
+
cm.doc.scrollTop = val
|
|
173
|
+
cm.display.scrollbars.setScrollTop(val)
|
|
174
|
+
if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Sync scroller and scrollbar, ensure the gutter elements are
|
|
178
|
+
// aligned.
|
|
179
|
+
export function setScrollLeft(cm, val, isScroller, forceScroll) {
|
|
180
|
+
val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth))
|
|
181
|
+
if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) return
|
|
182
|
+
cm.doc.scrollLeft = val
|
|
183
|
+
alignHorizontally(cm)
|
|
184
|
+
if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val
|
|
185
|
+
cm.display.scrollbars.setScrollLeft(val)
|
|
186
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Pos } from "../line/pos.js"
|
|
2
|
+
import { visualLine } from "../line/spans.js"
|
|
3
|
+
import { getLine } from "../line/utils_line.js"
|
|
4
|
+
import { charCoords, cursorCoords, displayWidth, paddingH, wrappedLineExtentChar } from "../measurement/position_measurement.js"
|
|
5
|
+
import { getOrder, iterateBidiSections } from "../util/bidi.js"
|
|
6
|
+
import { elt } from "../util/dom.js"
|
|
7
|
+
import { onBlur } from "./focus.js"
|
|
8
|
+
|
|
9
|
+
export function updateSelection(cm) {
|
|
10
|
+
cm.display.input.showSelection(cm.display.input.prepareSelection())
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function prepareSelection(cm, primary = true) {
|
|
14
|
+
let doc = cm.doc, result = {}
|
|
15
|
+
let curFragment = result.cursors = document.createDocumentFragment()
|
|
16
|
+
let selFragment = result.selection = document.createDocumentFragment()
|
|
17
|
+
|
|
18
|
+
let customCursor = cm.options.$customCursor
|
|
19
|
+
if (customCursor) primary = true
|
|
20
|
+
for (let i = 0; i < doc.sel.ranges.length; i++) {
|
|
21
|
+
if (!primary && i == doc.sel.primIndex) continue
|
|
22
|
+
let range = doc.sel.ranges[i]
|
|
23
|
+
if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) continue
|
|
24
|
+
let collapsed = range.empty()
|
|
25
|
+
if (customCursor) {
|
|
26
|
+
let head = customCursor(cm, range)
|
|
27
|
+
if (head) drawSelectionCursor(cm, head, curFragment)
|
|
28
|
+
} else if (collapsed || cm.options.showCursorWhenSelecting) {
|
|
29
|
+
drawSelectionCursor(cm, range.head, curFragment)
|
|
30
|
+
}
|
|
31
|
+
if (!collapsed)
|
|
32
|
+
drawSelectionRange(cm, range, selFragment)
|
|
33
|
+
}
|
|
34
|
+
return result
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Draws a cursor for the given range
|
|
38
|
+
export function drawSelectionCursor(cm, head, output) {
|
|
39
|
+
let pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine)
|
|
40
|
+
|
|
41
|
+
let cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"))
|
|
42
|
+
cursor.style.left = pos.left + "px"
|
|
43
|
+
cursor.style.top = pos.top + "px"
|
|
44
|
+
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"
|
|
45
|
+
|
|
46
|
+
if (/\bcm-fat-cursor\b/.test(cm.getWrapperElement().className)) {
|
|
47
|
+
let charPos = charCoords(cm, head, "div", null, null)
|
|
48
|
+
let width = charPos.right - charPos.left
|
|
49
|
+
cursor.style.width = (width > 0 ? width : cm.defaultCharWidth()) + "px"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (pos.other) {
|
|
53
|
+
// Secondary cursor, shown when on a 'jump' in bi-directional text
|
|
54
|
+
let otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"))
|
|
55
|
+
otherCursor.style.display = ""
|
|
56
|
+
otherCursor.style.left = pos.other.left + "px"
|
|
57
|
+
otherCursor.style.top = pos.other.top + "px"
|
|
58
|
+
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
|
|
63
|
+
|
|
64
|
+
// Draws the given range as a highlighted selection
|
|
65
|
+
function drawSelectionRange(cm, range, output) {
|
|
66
|
+
let display = cm.display, doc = cm.doc
|
|
67
|
+
let fragment = document.createDocumentFragment()
|
|
68
|
+
let padding = paddingH(cm.display), leftSide = padding.left
|
|
69
|
+
let rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
|
|
70
|
+
let docLTR = doc.direction == "ltr"
|
|
71
|
+
|
|
72
|
+
function add(left, top, width, bottom) {
|
|
73
|
+
if (top < 0) top = 0
|
|
74
|
+
top = Math.round(top)
|
|
75
|
+
bottom = Math.round(bottom)
|
|
76
|
+
fragment.appendChild(elt("div", null, "CodeMirror-selected", `position: absolute; left: ${left}px;
|
|
77
|
+
top: ${top}px; width: ${width == null ? rightSide - left : width}px;
|
|
78
|
+
height: ${bottom - top}px`))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function drawForLine(line, fromArg, toArg) {
|
|
82
|
+
let lineObj = getLine(doc, line)
|
|
83
|
+
let lineLen = lineObj.text.length
|
|
84
|
+
let start, end
|
|
85
|
+
function coords(ch, bias) {
|
|
86
|
+
return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function wrapX(pos, dir, side) {
|
|
90
|
+
let extent = wrappedLineExtentChar(cm, lineObj, null, pos)
|
|
91
|
+
let prop = (dir == "ltr") == (side == "after") ? "left" : "right"
|
|
92
|
+
let ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1)
|
|
93
|
+
return coords(ch, prop)[prop]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let order = getOrder(lineObj, doc.direction)
|
|
97
|
+
iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, (from, to, dir, i) => {
|
|
98
|
+
let ltr = dir == "ltr"
|
|
99
|
+
let fromPos = coords(from, ltr ? "left" : "right")
|
|
100
|
+
let toPos = coords(to - 1, ltr ? "right" : "left")
|
|
101
|
+
|
|
102
|
+
let openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen
|
|
103
|
+
let first = i == 0, last = !order || i == order.length - 1
|
|
104
|
+
if (toPos.top - fromPos.top <= 3) { // Single line
|
|
105
|
+
let openLeft = (docLTR ? openStart : openEnd) && first
|
|
106
|
+
let openRight = (docLTR ? openEnd : openStart) && last
|
|
107
|
+
let left = openLeft ? leftSide : (ltr ? fromPos : toPos).left
|
|
108
|
+
let right = openRight ? rightSide : (ltr ? toPos : fromPos).right
|
|
109
|
+
add(left, fromPos.top, right - left, fromPos.bottom)
|
|
110
|
+
} else { // Multiple lines
|
|
111
|
+
let topLeft, topRight, botLeft, botRight
|
|
112
|
+
if (ltr) {
|
|
113
|
+
topLeft = docLTR && openStart && first ? leftSide : fromPos.left
|
|
114
|
+
topRight = docLTR ? rightSide : wrapX(from, dir, "before")
|
|
115
|
+
botLeft = docLTR ? leftSide : wrapX(to, dir, "after")
|
|
116
|
+
botRight = docLTR && openEnd && last ? rightSide : toPos.right
|
|
117
|
+
} else {
|
|
118
|
+
topLeft = !docLTR ? leftSide : wrapX(from, dir, "before")
|
|
119
|
+
topRight = !docLTR && openStart && first ? rightSide : fromPos.right
|
|
120
|
+
botLeft = !docLTR && openEnd && last ? leftSide : toPos.left
|
|
121
|
+
botRight = !docLTR ? rightSide : wrapX(to, dir, "after")
|
|
122
|
+
}
|
|
123
|
+
add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom)
|
|
124
|
+
if (fromPos.bottom < toPos.top) add(leftSide, fromPos.bottom, null, toPos.top)
|
|
125
|
+
add(botLeft, toPos.top, botRight - botLeft, toPos.bottom)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!start || cmpCoords(fromPos, start) < 0) start = fromPos
|
|
129
|
+
if (cmpCoords(toPos, start) < 0) start = toPos
|
|
130
|
+
if (!end || cmpCoords(fromPos, end) < 0) end = fromPos
|
|
131
|
+
if (cmpCoords(toPos, end) < 0) end = toPos
|
|
132
|
+
})
|
|
133
|
+
return {start: start, end: end}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let sFrom = range.from(), sTo = range.to()
|
|
137
|
+
if (sFrom.line == sTo.line) {
|
|
138
|
+
drawForLine(sFrom.line, sFrom.ch, sTo.ch)
|
|
139
|
+
} else {
|
|
140
|
+
let fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line)
|
|
141
|
+
let singleVLine = visualLine(fromLine) == visualLine(toLine)
|
|
142
|
+
let leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end
|
|
143
|
+
let rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start
|
|
144
|
+
if (singleVLine) {
|
|
145
|
+
if (leftEnd.top < rightStart.top - 2) {
|
|
146
|
+
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom)
|
|
147
|
+
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom)
|
|
148
|
+
} else {
|
|
149
|
+
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (leftEnd.bottom < rightStart.top)
|
|
153
|
+
add(leftSide, leftEnd.bottom, null, rightStart.top)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
output.appendChild(fragment)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Cursor-blinking
|
|
160
|
+
export function restartBlink(cm) {
|
|
161
|
+
if (!cm.state.focused) return
|
|
162
|
+
let display = cm.display
|
|
163
|
+
clearInterval(display.blinker)
|
|
164
|
+
let on = true
|
|
165
|
+
display.cursorDiv.style.visibility = ""
|
|
166
|
+
if (cm.options.cursorBlinkRate > 0)
|
|
167
|
+
display.blinker = setInterval(() => {
|
|
168
|
+
if (!cm.hasFocus()) onBlur(cm)
|
|
169
|
+
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"
|
|
170
|
+
}, cm.options.cursorBlinkRate)
|
|
171
|
+
else if (cm.options.cursorBlinkRate < 0)
|
|
172
|
+
display.cursorDiv.style.visibility = "hidden"
|
|
173
|
+
}
|