@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,417 @@
|
|
|
1
|
+
import { delayBlurEvent, ensureFocus } from "../display/focus.js"
|
|
2
|
+
import { operation } from "../display/operations.js"
|
|
3
|
+
import { visibleLines } from "../display/update_lines.js"
|
|
4
|
+
import { clipPos, cmp, maxPos, minPos, Pos } from "../line/pos.js"
|
|
5
|
+
import { getLine, lineAtHeight } from "../line/utils_line.js"
|
|
6
|
+
import { posFromMouse } from "../measurement/position_measurement.js"
|
|
7
|
+
import { eventInWidget } from "../measurement/widgets.js"
|
|
8
|
+
import { normalizeSelection, Range, Selection } from "../model/selection.js"
|
|
9
|
+
import { extendRange, extendSelection, replaceOneSelection, setSelection } from "../model/selection_updates.js"
|
|
10
|
+
import { captureRightClick, chromeOS, ie, ie_version, mac, webkit, safari } from "../util/browser.js"
|
|
11
|
+
import { getOrder, getBidiPartAt } from "../util/bidi.js"
|
|
12
|
+
import { activeElt, doc as getDoc, win } from "../util/dom.js"
|
|
13
|
+
import { e_button, e_defaultPrevented, e_preventDefault, e_target, hasHandler, off, on, signal, signalDOMEvent } from "../util/event.js"
|
|
14
|
+
import { dragAndDrop } from "../util/feature_detection.js"
|
|
15
|
+
import { bind, countColumn, findColumn, sel_mouse } from "../util/misc.js"
|
|
16
|
+
import { addModifierNames } from "../input/keymap.js"
|
|
17
|
+
import { Pass } from "../util/misc.js"
|
|
18
|
+
|
|
19
|
+
import { dispatchKey } from "./key_events.js"
|
|
20
|
+
import { commands } from "./commands.js"
|
|
21
|
+
|
|
22
|
+
const DOUBLECLICK_DELAY = 400
|
|
23
|
+
|
|
24
|
+
class PastClick {
|
|
25
|
+
constructor(time, pos, button) {
|
|
26
|
+
this.time = time
|
|
27
|
+
this.pos = pos
|
|
28
|
+
this.button = button
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
compare(time, pos, button) {
|
|
32
|
+
return this.time + DOUBLECLICK_DELAY > time &&
|
|
33
|
+
cmp(pos, this.pos) == 0 && button == this.button
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let lastClick, lastDoubleClick
|
|
38
|
+
function clickRepeat(pos, button) {
|
|
39
|
+
let now = +new Date
|
|
40
|
+
if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
|
|
41
|
+
lastClick = lastDoubleClick = null
|
|
42
|
+
return "triple"
|
|
43
|
+
} else if (lastClick && lastClick.compare(now, pos, button)) {
|
|
44
|
+
lastDoubleClick = new PastClick(now, pos, button)
|
|
45
|
+
lastClick = null
|
|
46
|
+
return "double"
|
|
47
|
+
} else {
|
|
48
|
+
lastClick = new PastClick(now, pos, button)
|
|
49
|
+
lastDoubleClick = null
|
|
50
|
+
return "single"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A mouse down can be a single click, double click, triple click,
|
|
55
|
+
// start of selection drag, start of text drag, new cursor
|
|
56
|
+
// (ctrl-click), rectangle drag (alt-drag), or xwin
|
|
57
|
+
// middle-click-paste. Or it might be a click on something we should
|
|
58
|
+
// not interfere with, such as a scrollbar or widget.
|
|
59
|
+
export function onMouseDown(e) {
|
|
60
|
+
let cm = this, display = cm.display
|
|
61
|
+
if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) return
|
|
62
|
+
display.input.ensurePolled()
|
|
63
|
+
display.shift = e.shiftKey
|
|
64
|
+
|
|
65
|
+
if (eventInWidget(display, e)) {
|
|
66
|
+
if (!webkit) {
|
|
67
|
+
// Briefly turn off draggability, to allow widgets to do
|
|
68
|
+
// normal dragging things.
|
|
69
|
+
display.scroller.draggable = false
|
|
70
|
+
setTimeout(() => display.scroller.draggable = true, 100)
|
|
71
|
+
}
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
if (clickInGutter(cm, e)) return
|
|
75
|
+
let pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single"
|
|
76
|
+
win(cm).focus()
|
|
77
|
+
|
|
78
|
+
// #3261: make sure, that we're not starting a second selection
|
|
79
|
+
if (button == 1 && cm.state.selectingText)
|
|
80
|
+
cm.state.selectingText(e)
|
|
81
|
+
|
|
82
|
+
if (pos && handleMappedButton(cm, button, pos, repeat, e)) return
|
|
83
|
+
|
|
84
|
+
if (button == 1) {
|
|
85
|
+
if (pos) leftButtonDown(cm, pos, repeat, e)
|
|
86
|
+
else if (e_target(e) == display.scroller) e_preventDefault(e)
|
|
87
|
+
} else if (button == 2) {
|
|
88
|
+
if (pos) extendSelection(cm.doc, pos)
|
|
89
|
+
setTimeout(() => display.input.focus(), 20)
|
|
90
|
+
} else if (button == 3) {
|
|
91
|
+
if (captureRightClick) cm.display.input.onContextMenu(e)
|
|
92
|
+
else delayBlurEvent(cm)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function handleMappedButton(cm, button, pos, repeat, event) {
|
|
97
|
+
let name = "Click"
|
|
98
|
+
if (repeat == "double") name = "Double" + name
|
|
99
|
+
else if (repeat == "triple") name = "Triple" + name
|
|
100
|
+
name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name
|
|
101
|
+
|
|
102
|
+
return dispatchKey(cm, addModifierNames(name, event), event, bound => {
|
|
103
|
+
if (typeof bound == "string") bound = commands[bound]
|
|
104
|
+
if (!bound) return false
|
|
105
|
+
let done = false
|
|
106
|
+
try {
|
|
107
|
+
if (cm.isReadOnly()) cm.state.suppressEdits = true
|
|
108
|
+
done = bound(cm, pos) != Pass
|
|
109
|
+
} finally {
|
|
110
|
+
cm.state.suppressEdits = false
|
|
111
|
+
}
|
|
112
|
+
return done
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function configureMouse(cm, repeat, event) {
|
|
117
|
+
let option = cm.getOption("configureMouse")
|
|
118
|
+
let value = option ? option(cm, repeat, event) : {}
|
|
119
|
+
if (value.unit == null) {
|
|
120
|
+
let rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey
|
|
121
|
+
value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line"
|
|
122
|
+
}
|
|
123
|
+
if (value.extend == null || cm.doc.extend) value.extend = cm.doc.extend || event.shiftKey
|
|
124
|
+
if (value.addNew == null) value.addNew = mac ? event.metaKey : event.ctrlKey
|
|
125
|
+
if (value.moveOnDrag == null) value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey)
|
|
126
|
+
return value
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function leftButtonDown(cm, pos, repeat, event) {
|
|
130
|
+
if (ie) setTimeout(bind(ensureFocus, cm), 0)
|
|
131
|
+
else cm.curOp.focus = activeElt(getDoc(cm))
|
|
132
|
+
|
|
133
|
+
let behavior = configureMouse(cm, repeat, event)
|
|
134
|
+
|
|
135
|
+
let sel = cm.doc.sel, contained
|
|
136
|
+
if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
|
|
137
|
+
repeat == "single" && (contained = sel.contains(pos)) > -1 &&
|
|
138
|
+
(cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
|
|
139
|
+
(cmp(contained.to(), pos) > 0 || pos.xRel < 0))
|
|
140
|
+
leftButtonStartDrag(cm, event, pos, behavior)
|
|
141
|
+
else
|
|
142
|
+
leftButtonSelect(cm, event, pos, behavior)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Start a text drag. When it ends, see if any dragging actually
|
|
146
|
+
// happen, and treat as a click if it didn't.
|
|
147
|
+
function leftButtonStartDrag(cm, event, pos, behavior) {
|
|
148
|
+
let display = cm.display, moved = false
|
|
149
|
+
let dragEnd = operation(cm, e => {
|
|
150
|
+
if (webkit) display.scroller.draggable = false
|
|
151
|
+
cm.state.draggingText = false
|
|
152
|
+
if (cm.state.delayingBlurEvent) {
|
|
153
|
+
if (cm.hasFocus()) cm.state.delayingBlurEvent = false
|
|
154
|
+
else delayBlurEvent(cm)
|
|
155
|
+
}
|
|
156
|
+
off(display.wrapper.ownerDocument, "mouseup", dragEnd)
|
|
157
|
+
off(display.wrapper.ownerDocument, "mousemove", mouseMove)
|
|
158
|
+
off(display.scroller, "dragstart", dragStart)
|
|
159
|
+
off(display.scroller, "drop", dragEnd)
|
|
160
|
+
if (!moved) {
|
|
161
|
+
e_preventDefault(e)
|
|
162
|
+
if (!behavior.addNew)
|
|
163
|
+
extendSelection(cm.doc, pos, null, null, behavior.extend)
|
|
164
|
+
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
|
|
165
|
+
if ((webkit && !safari) || ie && ie_version == 9)
|
|
166
|
+
setTimeout(() => {display.wrapper.ownerDocument.body.focus({preventScroll: true}); display.input.focus()}, 20)
|
|
167
|
+
else
|
|
168
|
+
display.input.focus()
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
let mouseMove = function(e2) {
|
|
172
|
+
moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10
|
|
173
|
+
}
|
|
174
|
+
let dragStart = () => moved = true
|
|
175
|
+
// Let the drag handler handle this.
|
|
176
|
+
if (webkit) display.scroller.draggable = true
|
|
177
|
+
cm.state.draggingText = dragEnd
|
|
178
|
+
dragEnd.copy = !behavior.moveOnDrag
|
|
179
|
+
on(display.wrapper.ownerDocument, "mouseup", dragEnd)
|
|
180
|
+
on(display.wrapper.ownerDocument, "mousemove", mouseMove)
|
|
181
|
+
on(display.scroller, "dragstart", dragStart)
|
|
182
|
+
on(display.scroller, "drop", dragEnd)
|
|
183
|
+
|
|
184
|
+
cm.state.delayingBlurEvent = true
|
|
185
|
+
setTimeout(() => display.input.focus(), 20)
|
|
186
|
+
// IE's approach to draggable
|
|
187
|
+
if (display.scroller.dragDrop) display.scroller.dragDrop()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function rangeForUnit(cm, pos, unit) {
|
|
191
|
+
if (unit == "char") return new Range(pos, pos)
|
|
192
|
+
if (unit == "word") return cm.findWordAt(pos)
|
|
193
|
+
if (unit == "line") return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)))
|
|
194
|
+
let result = unit(cm, pos)
|
|
195
|
+
return new Range(result.from, result.to)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Normal selection, as opposed to text dragging.
|
|
199
|
+
function leftButtonSelect(cm, event, start, behavior) {
|
|
200
|
+
if (ie) delayBlurEvent(cm)
|
|
201
|
+
let display = cm.display, doc = cm.doc
|
|
202
|
+
e_preventDefault(event)
|
|
203
|
+
|
|
204
|
+
let ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges
|
|
205
|
+
if (behavior.addNew && !behavior.extend) {
|
|
206
|
+
ourIndex = doc.sel.contains(start)
|
|
207
|
+
if (ourIndex > -1)
|
|
208
|
+
ourRange = ranges[ourIndex]
|
|
209
|
+
else
|
|
210
|
+
ourRange = new Range(start, start)
|
|
211
|
+
} else {
|
|
212
|
+
ourRange = doc.sel.primary()
|
|
213
|
+
ourIndex = doc.sel.primIndex
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (behavior.unit == "rectangle") {
|
|
217
|
+
if (!behavior.addNew) ourRange = new Range(start, start)
|
|
218
|
+
start = posFromMouse(cm, event, true, true)
|
|
219
|
+
ourIndex = -1
|
|
220
|
+
} else {
|
|
221
|
+
let range = rangeForUnit(cm, start, behavior.unit)
|
|
222
|
+
if (behavior.extend)
|
|
223
|
+
ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend)
|
|
224
|
+
else
|
|
225
|
+
ourRange = range
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!behavior.addNew) {
|
|
229
|
+
ourIndex = 0
|
|
230
|
+
setSelection(doc, new Selection([ourRange], 0), sel_mouse)
|
|
231
|
+
startSel = doc.sel
|
|
232
|
+
} else if (ourIndex == -1) {
|
|
233
|
+
ourIndex = ranges.length
|
|
234
|
+
setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
|
|
235
|
+
{scroll: false, origin: "*mouse"})
|
|
236
|
+
} else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
|
|
237
|
+
setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
|
|
238
|
+
{scroll: false, origin: "*mouse"})
|
|
239
|
+
startSel = doc.sel
|
|
240
|
+
} else {
|
|
241
|
+
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let lastPos = start
|
|
245
|
+
function extendTo(pos) {
|
|
246
|
+
if (cmp(lastPos, pos) == 0) return
|
|
247
|
+
lastPos = pos
|
|
248
|
+
|
|
249
|
+
if (behavior.unit == "rectangle") {
|
|
250
|
+
let ranges = [], tabSize = cm.options.tabSize
|
|
251
|
+
let startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize)
|
|
252
|
+
let posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize)
|
|
253
|
+
let left = Math.min(startCol, posCol), right = Math.max(startCol, posCol)
|
|
254
|
+
for (let line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
|
|
255
|
+
line <= end; line++) {
|
|
256
|
+
let text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize)
|
|
257
|
+
if (left == right)
|
|
258
|
+
ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)))
|
|
259
|
+
else if (text.length > leftPos)
|
|
260
|
+
ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))))
|
|
261
|
+
}
|
|
262
|
+
if (!ranges.length) ranges.push(new Range(start, start))
|
|
263
|
+
setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
|
|
264
|
+
{origin: "*mouse", scroll: false})
|
|
265
|
+
cm.scrollIntoView(pos)
|
|
266
|
+
} else {
|
|
267
|
+
let oldRange = ourRange
|
|
268
|
+
let range = rangeForUnit(cm, pos, behavior.unit)
|
|
269
|
+
let anchor = oldRange.anchor, head
|
|
270
|
+
if (cmp(range.anchor, anchor) > 0) {
|
|
271
|
+
head = range.head
|
|
272
|
+
anchor = minPos(oldRange.from(), range.anchor)
|
|
273
|
+
} else {
|
|
274
|
+
head = range.anchor
|
|
275
|
+
anchor = maxPos(oldRange.to(), range.head)
|
|
276
|
+
}
|
|
277
|
+
let ranges = startSel.ranges.slice(0)
|
|
278
|
+
ranges[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head))
|
|
279
|
+
setSelection(doc, normalizeSelection(cm, ranges, ourIndex), sel_mouse)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
let editorSize = display.wrapper.getBoundingClientRect()
|
|
284
|
+
// Used to ensure timeout re-tries don't fire when another extend
|
|
285
|
+
// happened in the meantime (clearTimeout isn't reliable -- at
|
|
286
|
+
// least on Chrome, the timeouts still happen even when cleared,
|
|
287
|
+
// if the clear happens after their scheduled firing time).
|
|
288
|
+
let counter = 0
|
|
289
|
+
|
|
290
|
+
function extend(e) {
|
|
291
|
+
let curCount = ++counter
|
|
292
|
+
let cur = posFromMouse(cm, e, true, behavior.unit == "rectangle")
|
|
293
|
+
if (!cur) return
|
|
294
|
+
if (cmp(cur, lastPos) != 0) {
|
|
295
|
+
cm.curOp.focus = activeElt(getDoc(cm))
|
|
296
|
+
extendTo(cur)
|
|
297
|
+
let visible = visibleLines(display, doc)
|
|
298
|
+
if (cur.line >= visible.to || cur.line < visible.from)
|
|
299
|
+
setTimeout(operation(cm, () => {if (counter == curCount) extend(e)}), 150)
|
|
300
|
+
} else {
|
|
301
|
+
let outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0
|
|
302
|
+
if (outside) setTimeout(operation(cm, () => {
|
|
303
|
+
if (counter != curCount) return
|
|
304
|
+
display.scroller.scrollTop += outside
|
|
305
|
+
extend(e)
|
|
306
|
+
}), 50)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function done(e) {
|
|
311
|
+
cm.state.selectingText = false
|
|
312
|
+
counter = Infinity
|
|
313
|
+
// If e is null or undefined we interpret this as someone trying
|
|
314
|
+
// to explicitly cancel the selection rather than the user
|
|
315
|
+
// letting go of the mouse button.
|
|
316
|
+
if (e) {
|
|
317
|
+
e_preventDefault(e)
|
|
318
|
+
display.input.focus()
|
|
319
|
+
}
|
|
320
|
+
off(display.wrapper.ownerDocument, "mousemove", move)
|
|
321
|
+
off(display.wrapper.ownerDocument, "mouseup", up)
|
|
322
|
+
doc.history.lastSelOrigin = null
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let move = operation(cm, e => {
|
|
326
|
+
if (e.buttons === 0 || !e_button(e)) done(e)
|
|
327
|
+
else extend(e)
|
|
328
|
+
})
|
|
329
|
+
let up = operation(cm, done)
|
|
330
|
+
cm.state.selectingText = up
|
|
331
|
+
on(display.wrapper.ownerDocument, "mousemove", move)
|
|
332
|
+
on(display.wrapper.ownerDocument, "mouseup", up)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Used when mouse-selecting to adjust the anchor to the proper side
|
|
336
|
+
// of a bidi jump depending on the visual position of the head.
|
|
337
|
+
function bidiSimplify(cm, range) {
|
|
338
|
+
let {anchor, head} = range, anchorLine = getLine(cm.doc, anchor.line)
|
|
339
|
+
if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) return range
|
|
340
|
+
let order = getOrder(anchorLine)
|
|
341
|
+
if (!order) return range
|
|
342
|
+
let index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index]
|
|
343
|
+
if (part.from != anchor.ch && part.to != anchor.ch) return range
|
|
344
|
+
let boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1)
|
|
345
|
+
if (boundary == 0 || boundary == order.length) return range
|
|
346
|
+
|
|
347
|
+
// Compute the relative visual position of the head compared to the
|
|
348
|
+
// anchor (<0 is to the left, >0 to the right)
|
|
349
|
+
let leftSide
|
|
350
|
+
if (head.line != anchor.line) {
|
|
351
|
+
leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0
|
|
352
|
+
} else {
|
|
353
|
+
let headIndex = getBidiPartAt(order, head.ch, head.sticky)
|
|
354
|
+
let dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1)
|
|
355
|
+
if (headIndex == boundary - 1 || headIndex == boundary)
|
|
356
|
+
leftSide = dir < 0
|
|
357
|
+
else
|
|
358
|
+
leftSide = dir > 0
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
let usePart = order[boundary + (leftSide ? -1 : 0)]
|
|
362
|
+
let from = leftSide == (usePart.level == 1)
|
|
363
|
+
let ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before"
|
|
364
|
+
return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
// Determines whether an event happened in the gutter, and fires the
|
|
369
|
+
// handlers for the corresponding event.
|
|
370
|
+
function gutterEvent(cm, e, type, prevent) {
|
|
371
|
+
let mX, mY
|
|
372
|
+
if (e.touches) {
|
|
373
|
+
mX = e.touches[0].clientX
|
|
374
|
+
mY = e.touches[0].clientY
|
|
375
|
+
} else {
|
|
376
|
+
try { mX = e.clientX; mY = e.clientY }
|
|
377
|
+
catch(e) { return false }
|
|
378
|
+
}
|
|
379
|
+
if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false
|
|
380
|
+
if (prevent) e_preventDefault(e)
|
|
381
|
+
|
|
382
|
+
let display = cm.display
|
|
383
|
+
let lineBox = display.lineDiv.getBoundingClientRect()
|
|
384
|
+
|
|
385
|
+
if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e)
|
|
386
|
+
mY -= lineBox.top - display.viewOffset
|
|
387
|
+
|
|
388
|
+
for (let i = 0; i < cm.display.gutterSpecs.length; ++i) {
|
|
389
|
+
let g = display.gutters.childNodes[i]
|
|
390
|
+
if (g && g.getBoundingClientRect().right >= mX) {
|
|
391
|
+
let line = lineAtHeight(cm.doc, mY)
|
|
392
|
+
let gutter = cm.display.gutterSpecs[i]
|
|
393
|
+
signal(cm, type, cm, line, gutter.className, e)
|
|
394
|
+
return e_defaultPrevented(e)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function clickInGutter(cm, e) {
|
|
400
|
+
return gutterEvent(cm, e, "gutterClick", true)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// CONTEXT MENU HANDLING
|
|
404
|
+
|
|
405
|
+
// To make the context menu work, we need to briefly unhide the
|
|
406
|
+
// textarea (making it as unobtrusive as possible) to let the
|
|
407
|
+
// right-click take effect on it.
|
|
408
|
+
export function onContextMenu(cm, e) {
|
|
409
|
+
if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) return
|
|
410
|
+
if (signalDOMEvent(cm, e, "contextmenu")) return
|
|
411
|
+
if (!captureRightClick) cm.display.input.onContextMenu(e)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function contextMenuInGutter(cm, e) {
|
|
415
|
+
if (!hasHandler(cm, "gutterContextMenu")) return false
|
|
416
|
+
return gutterEvent(cm, e, "gutterContextMenu", false)
|
|
417
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { onBlur } from "../display/focus.js"
|
|
2
|
+
import { getGutters, updateGutters } from "../display/gutters.js"
|
|
3
|
+
import { loadMode, resetModeState } from "../display/mode_state.js"
|
|
4
|
+
import { initScrollbars, updateScrollbars } from "../display/scrollbars.js"
|
|
5
|
+
import { updateSelection } from "../display/selection.js"
|
|
6
|
+
import { regChange } from "../display/view_tracking.js"
|
|
7
|
+
import { getKeyMap } from "../input/keymap.js"
|
|
8
|
+
import { defaultSpecialCharPlaceholder } from "../line/line_data.js"
|
|
9
|
+
import { Pos } from "../line/pos.js"
|
|
10
|
+
import { findMaxLine } from "../line/spans.js"
|
|
11
|
+
import { clearCaches, compensateForHScroll, estimateLineHeights } from "../measurement/position_measurement.js"
|
|
12
|
+
import { replaceRange } from "../model/changes.js"
|
|
13
|
+
import { mobile, windows } from "../util/browser.js"
|
|
14
|
+
import { addClass, rmClass } from "../util/dom.js"
|
|
15
|
+
import { off, on } from "../util/event.js"
|
|
16
|
+
|
|
17
|
+
import { themeChanged } from "./utils.js"
|
|
18
|
+
|
|
19
|
+
export let Init = {toString: function(){return "CodeMirror.Init"}}
|
|
20
|
+
|
|
21
|
+
export let defaults = {}
|
|
22
|
+
export let optionHandlers = {}
|
|
23
|
+
|
|
24
|
+
export function defineOptions(CodeMirror) {
|
|
25
|
+
let optionHandlers = CodeMirror.optionHandlers
|
|
26
|
+
|
|
27
|
+
function option(name, deflt, handle, notOnInit) {
|
|
28
|
+
CodeMirror.defaults[name] = deflt
|
|
29
|
+
if (handle) optionHandlers[name] =
|
|
30
|
+
notOnInit ? (cm, val, old) => {if (old != Init) handle(cm, val, old)} : handle
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
CodeMirror.defineOption = option
|
|
34
|
+
|
|
35
|
+
// Passed to option handlers when there is no old value.
|
|
36
|
+
CodeMirror.Init = Init
|
|
37
|
+
|
|
38
|
+
// These two are, on init, called from the constructor because they
|
|
39
|
+
// have to be initialized before the editor can start at all.
|
|
40
|
+
option("value", "", (cm, val) => cm.setValue(val), true)
|
|
41
|
+
option("mode", null, (cm, val) => {
|
|
42
|
+
cm.doc.modeOption = val
|
|
43
|
+
loadMode(cm)
|
|
44
|
+
}, true)
|
|
45
|
+
|
|
46
|
+
option("indentUnit", 2, loadMode, true)
|
|
47
|
+
option("indentWithTabs", false)
|
|
48
|
+
option("smartIndent", true)
|
|
49
|
+
option("tabSize", 4, cm => {
|
|
50
|
+
resetModeState(cm)
|
|
51
|
+
clearCaches(cm)
|
|
52
|
+
regChange(cm)
|
|
53
|
+
}, true)
|
|
54
|
+
|
|
55
|
+
option("lineSeparator", null, (cm, val) => {
|
|
56
|
+
cm.doc.lineSep = val
|
|
57
|
+
if (!val) return
|
|
58
|
+
let newBreaks = [], lineNo = cm.doc.first
|
|
59
|
+
cm.doc.iter(line => {
|
|
60
|
+
for (let pos = 0;;) {
|
|
61
|
+
let found = line.text.indexOf(val, pos)
|
|
62
|
+
if (found == -1) break
|
|
63
|
+
pos = found + val.length
|
|
64
|
+
newBreaks.push(Pos(lineNo, found))
|
|
65
|
+
}
|
|
66
|
+
lineNo++
|
|
67
|
+
})
|
|
68
|
+
for (let i = newBreaks.length - 1; i >= 0; i--)
|
|
69
|
+
replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length))
|
|
70
|
+
})
|
|
71
|
+
option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\u202d\u202e\u2066\u2067\u2069\ufeff\ufff9-\ufffc]/g, (cm, val, old) => {
|
|
72
|
+
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g")
|
|
73
|
+
if (old != Init) cm.refresh()
|
|
74
|
+
})
|
|
75
|
+
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, cm => cm.refresh(), true)
|
|
76
|
+
option("electricChars", true)
|
|
77
|
+
option("inputStyle", mobile ? "contenteditable" : "textarea", () => {
|
|
78
|
+
throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
|
|
79
|
+
}, true)
|
|
80
|
+
option("spellcheck", false, (cm, val) => cm.getInputField().spellcheck = val, true)
|
|
81
|
+
option("autocorrect", false, (cm, val) => cm.getInputField().autocorrect = val, true)
|
|
82
|
+
option("autocapitalize", false, (cm, val) => cm.getInputField().autocapitalize = val, true)
|
|
83
|
+
option("rtlMoveVisually", !windows)
|
|
84
|
+
option("wholeLineUpdateBefore", true)
|
|
85
|
+
|
|
86
|
+
option("theme", "default", cm => {
|
|
87
|
+
themeChanged(cm)
|
|
88
|
+
updateGutters(cm)
|
|
89
|
+
}, true)
|
|
90
|
+
option("keyMap", "default", (cm, val, old) => {
|
|
91
|
+
let next = getKeyMap(val)
|
|
92
|
+
let prev = old != Init && getKeyMap(old)
|
|
93
|
+
if (prev && prev.detach) prev.detach(cm, next)
|
|
94
|
+
if (next.attach) next.attach(cm, prev || null)
|
|
95
|
+
})
|
|
96
|
+
option("extraKeys", null)
|
|
97
|
+
option("configureMouse", null)
|
|
98
|
+
|
|
99
|
+
option("lineWrapping", false, wrappingChanged, true)
|
|
100
|
+
option("gutters", [], (cm, val) => {
|
|
101
|
+
cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers)
|
|
102
|
+
updateGutters(cm)
|
|
103
|
+
}, true)
|
|
104
|
+
option("fixedGutter", true, (cm, val) => {
|
|
105
|
+
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
|
|
106
|
+
cm.refresh()
|
|
107
|
+
}, true)
|
|
108
|
+
option("coverGutterNextToScrollbar", false, cm => updateScrollbars(cm), true)
|
|
109
|
+
option("scrollbarStyle", "native", cm => {
|
|
110
|
+
initScrollbars(cm)
|
|
111
|
+
updateScrollbars(cm)
|
|
112
|
+
cm.display.scrollbars.setScrollTop(cm.doc.scrollTop)
|
|
113
|
+
cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft)
|
|
114
|
+
}, true)
|
|
115
|
+
option("lineNumbers", false, (cm, val) => {
|
|
116
|
+
cm.display.gutterSpecs = getGutters(cm.options.gutters, val)
|
|
117
|
+
updateGutters(cm)
|
|
118
|
+
}, true)
|
|
119
|
+
option("firstLineNumber", 1, updateGutters, true)
|
|
120
|
+
option("lineNumberFormatter", integer => integer, updateGutters, true)
|
|
121
|
+
option("showCursorWhenSelecting", false, updateSelection, true)
|
|
122
|
+
|
|
123
|
+
option("resetSelectionOnContextMenu", true)
|
|
124
|
+
option("lineWiseCopyCut", true)
|
|
125
|
+
option("pasteLinesPerSelection", true)
|
|
126
|
+
option("selectionsMayTouch", false)
|
|
127
|
+
|
|
128
|
+
option("readOnly", false, (cm, val) => {
|
|
129
|
+
if (val == "nocursor") {
|
|
130
|
+
onBlur(cm)
|
|
131
|
+
cm.display.input.blur()
|
|
132
|
+
}
|
|
133
|
+
cm.display.input.readOnlyChanged(val)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
option("screenReaderLabel", null, (cm, val) => {
|
|
137
|
+
val = (val === '') ? null : val
|
|
138
|
+
cm.display.input.screenReaderLabelChanged(val)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
option("disableInput", false, (cm, val) => {if (!val) cm.display.input.reset()}, true)
|
|
142
|
+
option("dragDrop", true, dragDropChanged)
|
|
143
|
+
option("allowDropFileTypes", null)
|
|
144
|
+
|
|
145
|
+
option("cursorBlinkRate", 530)
|
|
146
|
+
option("cursorScrollMargin", 0)
|
|
147
|
+
option("cursorHeight", 1, updateSelection, true)
|
|
148
|
+
option("singleCursorHeightPerLine", true, updateSelection, true)
|
|
149
|
+
option("workTime", 100)
|
|
150
|
+
option("workDelay", 100)
|
|
151
|
+
option("flattenSpans", true, resetModeState, true)
|
|
152
|
+
option("addModeClass", false, resetModeState, true)
|
|
153
|
+
option("pollInterval", 100)
|
|
154
|
+
option("undoDepth", 200, (cm, val) => cm.doc.history.undoDepth = val)
|
|
155
|
+
option("historyEventDelay", 1250)
|
|
156
|
+
option("viewportMargin", 10, cm => cm.refresh(), true)
|
|
157
|
+
option("maxHighlightLength", 10000, resetModeState, true)
|
|
158
|
+
option("moveInputWithCursor", true, (cm, val) => {
|
|
159
|
+
if (!val) cm.display.input.resetPosition()
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
option("tabindex", null, (cm, val) => cm.display.input.getField().tabIndex = val || "")
|
|
163
|
+
option("autofocus", null)
|
|
164
|
+
option("direction", "ltr", (cm, val) => cm.doc.setDirection(val), true)
|
|
165
|
+
option("phrases", null)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function dragDropChanged(cm, value, old) {
|
|
169
|
+
let wasOn = old && old != Init
|
|
170
|
+
if (!value != !wasOn) {
|
|
171
|
+
let funcs = cm.display.dragFunctions
|
|
172
|
+
let toggle = value ? on : off
|
|
173
|
+
toggle(cm.display.scroller, "dragstart", funcs.start)
|
|
174
|
+
toggle(cm.display.scroller, "dragenter", funcs.enter)
|
|
175
|
+
toggle(cm.display.scroller, "dragover", funcs.over)
|
|
176
|
+
toggle(cm.display.scroller, "dragleave", funcs.leave)
|
|
177
|
+
toggle(cm.display.scroller, "drop", funcs.drop)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function wrappingChanged(cm) {
|
|
182
|
+
if (cm.options.lineWrapping) {
|
|
183
|
+
addClass(cm.display.wrapper, "CodeMirror-wrap")
|
|
184
|
+
cm.display.sizer.style.minWidth = ""
|
|
185
|
+
cm.display.sizerWidth = null
|
|
186
|
+
} else {
|
|
187
|
+
rmClass(cm.display.wrapper, "CodeMirror-wrap")
|
|
188
|
+
findMaxLine(cm)
|
|
189
|
+
}
|
|
190
|
+
estimateLineHeights(cm)
|
|
191
|
+
regChange(cm)
|
|
192
|
+
clearCaches(cm)
|
|
193
|
+
setTimeout(() => updateScrollbars(cm), 100)
|
|
194
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { clearCaches } from "../measurement/position_measurement.js"
|
|
2
|
+
|
|
3
|
+
export function themeChanged(cm) {
|
|
4
|
+
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
|
|
5
|
+
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-")
|
|
6
|
+
clearCaches(cm)
|
|
7
|
+
}
|