@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,217 @@
|
|
|
1
|
+
import { Display } from "../display/Display.js"
|
|
2
|
+
import { onFocus, onBlur } from "../display/focus.js"
|
|
3
|
+
import { maybeUpdateLineNumberWidth } from "../display/line_numbers.js"
|
|
4
|
+
import { endOperation, operation, startOperation } from "../display/operations.js"
|
|
5
|
+
import { initScrollbars } from "../display/scrollbars.js"
|
|
6
|
+
import { onScrollWheel } from "../display/scroll_events.js"
|
|
7
|
+
import { setScrollLeft, updateScrollTop } from "../display/scrolling.js"
|
|
8
|
+
import { clipPos, Pos } from "../line/pos.js"
|
|
9
|
+
import { posFromMouse } from "../measurement/position_measurement.js"
|
|
10
|
+
import { eventInWidget } from "../measurement/widgets.js"
|
|
11
|
+
import Doc from "../model/Doc.js"
|
|
12
|
+
import { attachDoc } from "../model/document_data.js"
|
|
13
|
+
import { Range } from "../model/selection.js"
|
|
14
|
+
import { extendSelection } from "../model/selection_updates.js"
|
|
15
|
+
import { ie, ie_version, mobile, webkit } from "../util/browser.js"
|
|
16
|
+
import { e_preventDefault, e_stop, on, signal, signalDOMEvent } from "../util/event.js"
|
|
17
|
+
import { copyObj, Delayed } from "../util/misc.js"
|
|
18
|
+
|
|
19
|
+
import { clearDragCursor, onDragOver, onDragStart, onDrop } from "./drop_events.js"
|
|
20
|
+
import { ensureGlobalHandlers } from "./global_events.js"
|
|
21
|
+
import { onKeyDown, onKeyPress, onKeyUp } from "./key_events.js"
|
|
22
|
+
import { clickInGutter, onContextMenu, onMouseDown } from "./mouse_events.js"
|
|
23
|
+
import { themeChanged } from "./utils.js"
|
|
24
|
+
import { defaults, optionHandlers, Init } from "./options.js"
|
|
25
|
+
|
|
26
|
+
// A CodeMirror instance represents an editor. This is the object
|
|
27
|
+
// that user code is usually dealing with.
|
|
28
|
+
|
|
29
|
+
export function CodeMirror(place, options) {
|
|
30
|
+
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options)
|
|
31
|
+
|
|
32
|
+
this.options = options = options ? copyObj(options) : {}
|
|
33
|
+
// Determine effective options based on given values and defaults.
|
|
34
|
+
copyObj(defaults, options, false)
|
|
35
|
+
|
|
36
|
+
let doc = options.value
|
|
37
|
+
if (typeof doc == "string") doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction)
|
|
38
|
+
else if (options.mode) doc.modeOption = options.mode
|
|
39
|
+
this.doc = doc
|
|
40
|
+
|
|
41
|
+
let input = new CodeMirror.inputStyles[options.inputStyle](this)
|
|
42
|
+
let display = this.display = new Display(place, doc, input, options)
|
|
43
|
+
display.wrapper.CodeMirror = this
|
|
44
|
+
themeChanged(this)
|
|
45
|
+
if (options.lineWrapping)
|
|
46
|
+
this.display.wrapper.className += " CodeMirror-wrap"
|
|
47
|
+
initScrollbars(this)
|
|
48
|
+
|
|
49
|
+
this.state = {
|
|
50
|
+
keyMaps: [], // stores maps added by addKeyMap
|
|
51
|
+
overlays: [], // highlighting overlays, as added by addOverlay
|
|
52
|
+
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
|
|
53
|
+
overwrite: false,
|
|
54
|
+
delayingBlurEvent: false,
|
|
55
|
+
focused: false,
|
|
56
|
+
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
|
|
57
|
+
pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll
|
|
58
|
+
selectingText: false,
|
|
59
|
+
draggingText: false,
|
|
60
|
+
highlight: new Delayed(), // stores highlight worker timeout
|
|
61
|
+
keySeq: null, // Unfinished key sequence
|
|
62
|
+
specialChars: null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.autofocus && !mobile) display.input.focus()
|
|
66
|
+
|
|
67
|
+
// Override magic textarea content restore that IE sometimes does
|
|
68
|
+
// on our hidden textarea on reload
|
|
69
|
+
if (ie && ie_version < 11) setTimeout(() => this.display.input.reset(true), 20)
|
|
70
|
+
|
|
71
|
+
registerEventHandlers(this)
|
|
72
|
+
ensureGlobalHandlers()
|
|
73
|
+
|
|
74
|
+
startOperation(this)
|
|
75
|
+
this.curOp.forceUpdate = true
|
|
76
|
+
attachDoc(this, doc)
|
|
77
|
+
|
|
78
|
+
if ((options.autofocus && !mobile) || this.hasFocus())
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
if (this.hasFocus() && !this.state.focused) onFocus(this)
|
|
81
|
+
}, 20)
|
|
82
|
+
else
|
|
83
|
+
onBlur(this)
|
|
84
|
+
|
|
85
|
+
for (let opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
|
|
86
|
+
optionHandlers[opt](this, options[opt], Init)
|
|
87
|
+
maybeUpdateLineNumberWidth(this)
|
|
88
|
+
if (options.finishInit) options.finishInit(this)
|
|
89
|
+
for (let i = 0; i < initHooks.length; ++i) initHooks[i](this)
|
|
90
|
+
endOperation(this)
|
|
91
|
+
// Suppress optimizelegibility in Webkit, since it breaks text
|
|
92
|
+
// measuring on line wrapping boundaries.
|
|
93
|
+
if (webkit && options.lineWrapping &&
|
|
94
|
+
getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
|
|
95
|
+
display.lineDiv.style.textRendering = "auto"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The default configuration options.
|
|
99
|
+
CodeMirror.defaults = defaults
|
|
100
|
+
// Functions to run when options are changed.
|
|
101
|
+
CodeMirror.optionHandlers = optionHandlers
|
|
102
|
+
|
|
103
|
+
export default CodeMirror
|
|
104
|
+
|
|
105
|
+
// Attach the necessary event handlers when initializing the editor
|
|
106
|
+
function registerEventHandlers(cm) {
|
|
107
|
+
let d = cm.display
|
|
108
|
+
on(d.scroller, "mousedown", operation(cm, onMouseDown))
|
|
109
|
+
// Older IE's will not fire a second mousedown for a double click
|
|
110
|
+
if (ie && ie_version < 11)
|
|
111
|
+
on(d.scroller, "dblclick", operation(cm, e => {
|
|
112
|
+
if (signalDOMEvent(cm, e)) return
|
|
113
|
+
let pos = posFromMouse(cm, e)
|
|
114
|
+
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return
|
|
115
|
+
e_preventDefault(e)
|
|
116
|
+
let word = cm.findWordAt(pos)
|
|
117
|
+
extendSelection(cm.doc, word.anchor, word.head)
|
|
118
|
+
}))
|
|
119
|
+
else
|
|
120
|
+
on(d.scroller, "dblclick", e => signalDOMEvent(cm, e) || e_preventDefault(e))
|
|
121
|
+
// Some browsers fire contextmenu *after* opening the menu, at
|
|
122
|
+
// which point we can't mess with it anymore. Context menu is
|
|
123
|
+
// handled in onMouseDown for these browsers.
|
|
124
|
+
on(d.scroller, "contextmenu", e => onContextMenu(cm, e))
|
|
125
|
+
on(d.input.getField(), "contextmenu", e => {
|
|
126
|
+
if (!d.scroller.contains(e.target)) onContextMenu(cm, e)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// Used to suppress mouse event handling when a touch happens
|
|
130
|
+
let touchFinished, prevTouch = {end: 0}
|
|
131
|
+
function finishTouch() {
|
|
132
|
+
if (d.activeTouch) {
|
|
133
|
+
touchFinished = setTimeout(() => d.activeTouch = null, 1000)
|
|
134
|
+
prevTouch = d.activeTouch
|
|
135
|
+
prevTouch.end = +new Date
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function isMouseLikeTouchEvent(e) {
|
|
139
|
+
if (e.touches.length != 1) return false
|
|
140
|
+
let touch = e.touches[0]
|
|
141
|
+
return touch.radiusX <= 1 && touch.radiusY <= 1
|
|
142
|
+
}
|
|
143
|
+
function farAway(touch, other) {
|
|
144
|
+
if (other.left == null) return true
|
|
145
|
+
let dx = other.left - touch.left, dy = other.top - touch.top
|
|
146
|
+
return dx * dx + dy * dy > 20 * 20
|
|
147
|
+
}
|
|
148
|
+
on(d.scroller, "touchstart", e => {
|
|
149
|
+
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
|
|
150
|
+
d.input.ensurePolled()
|
|
151
|
+
clearTimeout(touchFinished)
|
|
152
|
+
let now = +new Date
|
|
153
|
+
d.activeTouch = {start: now, moved: false,
|
|
154
|
+
prev: now - prevTouch.end <= 300 ? prevTouch : null}
|
|
155
|
+
if (e.touches.length == 1) {
|
|
156
|
+
d.activeTouch.left = e.touches[0].pageX
|
|
157
|
+
d.activeTouch.top = e.touches[0].pageY
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
on(d.scroller, "touchmove", () => {
|
|
162
|
+
if (d.activeTouch) d.activeTouch.moved = true
|
|
163
|
+
})
|
|
164
|
+
on(d.scroller, "touchend", e => {
|
|
165
|
+
let touch = d.activeTouch
|
|
166
|
+
if (touch && !eventInWidget(d, e) && touch.left != null &&
|
|
167
|
+
!touch.moved && new Date - touch.start < 300) {
|
|
168
|
+
let pos = cm.coordsChar(d.activeTouch, "page"), range
|
|
169
|
+
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
|
|
170
|
+
range = new Range(pos, pos)
|
|
171
|
+
else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
|
|
172
|
+
range = cm.findWordAt(pos)
|
|
173
|
+
else // Triple tap
|
|
174
|
+
range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)))
|
|
175
|
+
cm.setSelection(range.anchor, range.head)
|
|
176
|
+
cm.focus()
|
|
177
|
+
e_preventDefault(e)
|
|
178
|
+
}
|
|
179
|
+
finishTouch()
|
|
180
|
+
})
|
|
181
|
+
on(d.scroller, "touchcancel", finishTouch)
|
|
182
|
+
|
|
183
|
+
// Sync scrolling between fake scrollbars and real scrollable
|
|
184
|
+
// area, ensure viewport is updated when scrolling.
|
|
185
|
+
on(d.scroller, "scroll", () => {
|
|
186
|
+
if (d.scroller.clientHeight) {
|
|
187
|
+
updateScrollTop(cm, d.scroller.scrollTop)
|
|
188
|
+
setScrollLeft(cm, d.scroller.scrollLeft, true)
|
|
189
|
+
signal(cm, "scroll", cm)
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
// Listen to wheel events in order to try and update the viewport on time.
|
|
194
|
+
on(d.scroller, "mousewheel", e => onScrollWheel(cm, e))
|
|
195
|
+
on(d.scroller, "DOMMouseScroll", e => onScrollWheel(cm, e))
|
|
196
|
+
|
|
197
|
+
// Prevent wrapper from ever scrolling
|
|
198
|
+
on(d.wrapper, "scroll", () => d.wrapper.scrollTop = d.wrapper.scrollLeft = 0)
|
|
199
|
+
|
|
200
|
+
d.dragFunctions = {
|
|
201
|
+
enter: e => {if (!signalDOMEvent(cm, e)) e_stop(e)},
|
|
202
|
+
over: e => {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
|
|
203
|
+
start: e => onDragStart(cm, e),
|
|
204
|
+
drop: operation(cm, onDrop),
|
|
205
|
+
leave: e => {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let inp = d.input.getField()
|
|
209
|
+
on(inp, "keyup", e => onKeyUp.call(cm, e))
|
|
210
|
+
on(inp, "keydown", operation(cm, onKeyDown))
|
|
211
|
+
on(inp, "keypress", operation(cm, onKeyPress))
|
|
212
|
+
on(inp, "focus", e => onFocus(cm, e))
|
|
213
|
+
on(inp, "blur", e => onBlur(cm, e))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let initHooks = []
|
|
217
|
+
CodeMirror.defineInitHook = f => initHooks.push(f)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { deleteNearSelection } from "./deleteNearSelection.js"
|
|
2
|
+
import { runInOp } from "../display/operations.js"
|
|
3
|
+
import { ensureCursorVisible } from "../display/scrolling.js"
|
|
4
|
+
import { endOfLine } from "../input/movement.js"
|
|
5
|
+
import { clipPos, Pos } from "../line/pos.js"
|
|
6
|
+
import { visualLine, visualLineEnd } from "../line/spans.js"
|
|
7
|
+
import { getLine, lineNo } from "../line/utils_line.js"
|
|
8
|
+
import { Range } from "../model/selection.js"
|
|
9
|
+
import { selectAll } from "../model/selection_updates.js"
|
|
10
|
+
import { countColumn, sel_dontScroll, sel_move, spaceStr } from "../util/misc.js"
|
|
11
|
+
import { getOrder } from "../util/bidi.js"
|
|
12
|
+
|
|
13
|
+
// Commands are parameter-less actions that can be performed on an
|
|
14
|
+
// editor, mostly used for keybindings.
|
|
15
|
+
export let commands = {
|
|
16
|
+
selectAll: selectAll,
|
|
17
|
+
singleSelection: cm => cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll),
|
|
18
|
+
killLine: cm => deleteNearSelection(cm, range => {
|
|
19
|
+
if (range.empty()) {
|
|
20
|
+
let len = getLine(cm.doc, range.head.line).text.length
|
|
21
|
+
if (range.head.ch == len && range.head.line < cm.lastLine())
|
|
22
|
+
return {from: range.head, to: Pos(range.head.line + 1, 0)}
|
|
23
|
+
else
|
|
24
|
+
return {from: range.head, to: Pos(range.head.line, len)}
|
|
25
|
+
} else {
|
|
26
|
+
return {from: range.from(), to: range.to()}
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
deleteLine: cm => deleteNearSelection(cm, range => ({
|
|
30
|
+
from: Pos(range.from().line, 0),
|
|
31
|
+
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
|
|
32
|
+
})),
|
|
33
|
+
delLineLeft: cm => deleteNearSelection(cm, range => ({
|
|
34
|
+
from: Pos(range.from().line, 0), to: range.from()
|
|
35
|
+
})),
|
|
36
|
+
delWrappedLineLeft: cm => deleteNearSelection(cm, range => {
|
|
37
|
+
let top = cm.charCoords(range.head, "div").top + 5
|
|
38
|
+
let leftPos = cm.coordsChar({left: 0, top: top}, "div")
|
|
39
|
+
return {from: leftPos, to: range.from()}
|
|
40
|
+
}),
|
|
41
|
+
delWrappedLineRight: cm => deleteNearSelection(cm, range => {
|
|
42
|
+
let top = cm.charCoords(range.head, "div").top + 5
|
|
43
|
+
let rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
|
|
44
|
+
return {from: range.from(), to: rightPos }
|
|
45
|
+
}),
|
|
46
|
+
undo: cm => cm.undo(),
|
|
47
|
+
redo: cm => cm.redo(),
|
|
48
|
+
undoSelection: cm => cm.undoSelection(),
|
|
49
|
+
redoSelection: cm => cm.redoSelection(),
|
|
50
|
+
goDocStart: cm => cm.extendSelection(Pos(cm.firstLine(), 0)),
|
|
51
|
+
goDocEnd: cm => cm.extendSelection(Pos(cm.lastLine())),
|
|
52
|
+
goLineStart: cm => cm.extendSelectionsBy(range => lineStart(cm, range.head.line),
|
|
53
|
+
{origin: "+move", bias: 1}
|
|
54
|
+
),
|
|
55
|
+
goLineStartSmart: cm => cm.extendSelectionsBy(range => lineStartSmart(cm, range.head),
|
|
56
|
+
{origin: "+move", bias: 1}
|
|
57
|
+
),
|
|
58
|
+
goLineEnd: cm => cm.extendSelectionsBy(range => lineEnd(cm, range.head.line),
|
|
59
|
+
{origin: "+move", bias: -1}
|
|
60
|
+
),
|
|
61
|
+
goLineRight: cm => cm.extendSelectionsBy(range => {
|
|
62
|
+
let top = cm.cursorCoords(range.head, "div").top + 5
|
|
63
|
+
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
|
|
64
|
+
}, sel_move),
|
|
65
|
+
goLineLeft: cm => cm.extendSelectionsBy(range => {
|
|
66
|
+
let top = cm.cursorCoords(range.head, "div").top + 5
|
|
67
|
+
return cm.coordsChar({left: 0, top: top}, "div")
|
|
68
|
+
}, sel_move),
|
|
69
|
+
goLineLeftSmart: cm => cm.extendSelectionsBy(range => {
|
|
70
|
+
let top = cm.cursorCoords(range.head, "div").top + 5
|
|
71
|
+
let pos = cm.coordsChar({left: 0, top: top}, "div")
|
|
72
|
+
if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head)
|
|
73
|
+
return pos
|
|
74
|
+
}, sel_move),
|
|
75
|
+
goLineUp: cm => cm.moveV(-1, "line"),
|
|
76
|
+
goLineDown: cm => cm.moveV(1, "line"),
|
|
77
|
+
goPageUp: cm => cm.moveV(-1, "page"),
|
|
78
|
+
goPageDown: cm => cm.moveV(1, "page"),
|
|
79
|
+
goCharLeft: cm => cm.moveH(-1, "char"),
|
|
80
|
+
goCharRight: cm => cm.moveH(1, "char"),
|
|
81
|
+
goColumnLeft: cm => cm.moveH(-1, "column"),
|
|
82
|
+
goColumnRight: cm => cm.moveH(1, "column"),
|
|
83
|
+
goWordLeft: cm => cm.moveH(-1, "word"),
|
|
84
|
+
goGroupRight: cm => cm.moveH(1, "group"),
|
|
85
|
+
goGroupLeft: cm => cm.moveH(-1, "group"),
|
|
86
|
+
goWordRight: cm => cm.moveH(1, "word"),
|
|
87
|
+
delCharBefore: cm => cm.deleteH(-1, "codepoint"),
|
|
88
|
+
delCharAfter: cm => cm.deleteH(1, "char"),
|
|
89
|
+
delWordBefore: cm => cm.deleteH(-1, "word"),
|
|
90
|
+
delWordAfter: cm => cm.deleteH(1, "word"),
|
|
91
|
+
delGroupBefore: cm => cm.deleteH(-1, "group"),
|
|
92
|
+
delGroupAfter: cm => cm.deleteH(1, "group"),
|
|
93
|
+
indentAuto: cm => cm.indentSelection("smart"),
|
|
94
|
+
indentMore: cm => cm.indentSelection("add"),
|
|
95
|
+
indentLess: cm => cm.indentSelection("subtract"),
|
|
96
|
+
insertTab: cm => cm.replaceSelection("\t"),
|
|
97
|
+
insertSoftTab: cm => {
|
|
98
|
+
let spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize
|
|
99
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
100
|
+
let pos = ranges[i].from()
|
|
101
|
+
let col = countColumn(cm.getLine(pos.line), pos.ch, tabSize)
|
|
102
|
+
spaces.push(spaceStr(tabSize - col % tabSize))
|
|
103
|
+
}
|
|
104
|
+
cm.replaceSelections(spaces)
|
|
105
|
+
},
|
|
106
|
+
defaultTab: cm => {
|
|
107
|
+
if (cm.somethingSelected()) cm.indentSelection("add")
|
|
108
|
+
else cm.execCommand("insertTab")
|
|
109
|
+
},
|
|
110
|
+
// Swap the two chars left and right of each selection's head.
|
|
111
|
+
// Move cursor behind the two swapped characters afterwards.
|
|
112
|
+
//
|
|
113
|
+
// Doesn't consider line feeds a character.
|
|
114
|
+
// Doesn't scan more than one line above to find a character.
|
|
115
|
+
// Doesn't do anything on an empty line.
|
|
116
|
+
// Doesn't do anything with non-empty selections.
|
|
117
|
+
transposeChars: cm => runInOp(cm, () => {
|
|
118
|
+
let ranges = cm.listSelections(), newSel = []
|
|
119
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
120
|
+
if (!ranges[i].empty()) continue
|
|
121
|
+
let cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
|
|
122
|
+
if (line) {
|
|
123
|
+
if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1)
|
|
124
|
+
if (cur.ch > 0) {
|
|
125
|
+
cur = new Pos(cur.line, cur.ch + 1)
|
|
126
|
+
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
|
|
127
|
+
Pos(cur.line, cur.ch - 2), cur, "+transpose")
|
|
128
|
+
} else if (cur.line > cm.doc.first) {
|
|
129
|
+
let prev = getLine(cm.doc, cur.line - 1).text
|
|
130
|
+
if (prev) {
|
|
131
|
+
cur = new Pos(cur.line, 1)
|
|
132
|
+
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
|
|
133
|
+
prev.charAt(prev.length - 1),
|
|
134
|
+
Pos(cur.line - 1, prev.length - 1), cur, "+transpose")
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
newSel.push(new Range(cur, cur))
|
|
139
|
+
}
|
|
140
|
+
cm.setSelections(newSel)
|
|
141
|
+
}),
|
|
142
|
+
newlineAndIndent: cm => runInOp(cm, () => {
|
|
143
|
+
let sels = cm.listSelections()
|
|
144
|
+
for (let i = sels.length - 1; i >= 0; i--)
|
|
145
|
+
cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input")
|
|
146
|
+
sels = cm.listSelections()
|
|
147
|
+
for (let i = 0; i < sels.length; i++)
|
|
148
|
+
cm.indentLine(sels[i].from().line, null, true)
|
|
149
|
+
ensureCursorVisible(cm)
|
|
150
|
+
}),
|
|
151
|
+
openLine: cm => cm.replaceSelection("\n", "start"),
|
|
152
|
+
toggleOverwrite: cm => cm.toggleOverwrite()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
function lineStart(cm, lineN) {
|
|
157
|
+
let line = getLine(cm.doc, lineN)
|
|
158
|
+
let visual = visualLine(line)
|
|
159
|
+
if (visual != line) lineN = lineNo(visual)
|
|
160
|
+
return endOfLine(true, cm, visual, lineN, 1)
|
|
161
|
+
}
|
|
162
|
+
function lineEnd(cm, lineN) {
|
|
163
|
+
let line = getLine(cm.doc, lineN)
|
|
164
|
+
let visual = visualLineEnd(line)
|
|
165
|
+
if (visual != line) lineN = lineNo(visual)
|
|
166
|
+
return endOfLine(true, cm, line, lineN, -1)
|
|
167
|
+
}
|
|
168
|
+
function lineStartSmart(cm, pos) {
|
|
169
|
+
let start = lineStart(cm, pos.line)
|
|
170
|
+
let line = getLine(cm.doc, start.line)
|
|
171
|
+
let order = getOrder(line, cm.doc.direction)
|
|
172
|
+
if (!order || order[0].level == 0) {
|
|
173
|
+
let firstNonWS = Math.max(start.ch, line.text.search(/\S/))
|
|
174
|
+
let inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch
|
|
175
|
+
return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
|
|
176
|
+
}
|
|
177
|
+
return start
|
|
178
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { runInOp } from "../display/operations.js"
|
|
2
|
+
import { ensureCursorVisible } from "../display/scrolling.js"
|
|
3
|
+
import { cmp } from "../line/pos.js"
|
|
4
|
+
import { replaceRange } from "../model/changes.js"
|
|
5
|
+
import { lst } from "../util/misc.js"
|
|
6
|
+
|
|
7
|
+
// Helper for deleting text near the selection(s), used to implement
|
|
8
|
+
// backspace, delete, and similar functionality.
|
|
9
|
+
export function deleteNearSelection(cm, compute) {
|
|
10
|
+
let ranges = cm.doc.sel.ranges, kill = []
|
|
11
|
+
// Build up a set of ranges to kill first, merging overlapping
|
|
12
|
+
// ranges.
|
|
13
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
14
|
+
let toKill = compute(ranges[i])
|
|
15
|
+
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
|
|
16
|
+
let replaced = kill.pop()
|
|
17
|
+
if (cmp(replaced.from, toKill.from) < 0) {
|
|
18
|
+
toKill.from = replaced.from
|
|
19
|
+
break
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
kill.push(toKill)
|
|
23
|
+
}
|
|
24
|
+
// Next, remove those actual ranges.
|
|
25
|
+
runInOp(cm, () => {
|
|
26
|
+
for (let i = kill.length - 1; i >= 0; i--)
|
|
27
|
+
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete")
|
|
28
|
+
ensureCursorVisible(cm)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { drawSelectionCursor } from "../display/selection.js"
|
|
2
|
+
import { operation } from "../display/operations.js"
|
|
3
|
+
import { clipPos } from "../line/pos.js"
|
|
4
|
+
import { posFromMouse } from "../measurement/position_measurement.js"
|
|
5
|
+
import { eventInWidget } from "../measurement/widgets.js"
|
|
6
|
+
import { makeChange, replaceRange } from "../model/changes.js"
|
|
7
|
+
import { changeEnd } from "../model/change_measurement.js"
|
|
8
|
+
import { simpleSelection } from "../model/selection.js"
|
|
9
|
+
import { setSelectionNoUndo, setSelectionReplaceHistory } from "../model/selection_updates.js"
|
|
10
|
+
import { ie, presto, safari } from "../util/browser.js"
|
|
11
|
+
import { elt, removeChildrenAndAdd } from "../util/dom.js"
|
|
12
|
+
import { e_preventDefault, e_stop, signalDOMEvent } from "../util/event.js"
|
|
13
|
+
import { indexOf } from "../util/misc.js"
|
|
14
|
+
|
|
15
|
+
// Kludge to work around strange IE behavior where it'll sometimes
|
|
16
|
+
// re-fire a series of drag-related events right after the drop (#1551)
|
|
17
|
+
let lastDrop = 0
|
|
18
|
+
|
|
19
|
+
export function onDrop(e) {
|
|
20
|
+
let cm = this
|
|
21
|
+
clearDragCursor(cm)
|
|
22
|
+
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
|
|
23
|
+
return
|
|
24
|
+
e_preventDefault(e)
|
|
25
|
+
if (ie) lastDrop = +new Date
|
|
26
|
+
let pos = posFromMouse(cm, e, true), files = e.dataTransfer.files
|
|
27
|
+
if (!pos || cm.isReadOnly()) return
|
|
28
|
+
// Might be a file drop, in which case we simply extract the text
|
|
29
|
+
// and insert it.
|
|
30
|
+
if (files && files.length && window.FileReader && window.File) {
|
|
31
|
+
let n = files.length, text = Array(n), read = 0
|
|
32
|
+
const markAsReadAndPasteIfAllFilesAreRead = () => {
|
|
33
|
+
if (++read == n) {
|
|
34
|
+
operation(cm, () => {
|
|
35
|
+
pos = clipPos(cm.doc, pos)
|
|
36
|
+
let change = {from: pos, to: pos,
|
|
37
|
+
text: cm.doc.splitLines(
|
|
38
|
+
text.filter(t => t != null).join(cm.doc.lineSeparator())),
|
|
39
|
+
origin: "paste"}
|
|
40
|
+
makeChange(cm.doc, change)
|
|
41
|
+
setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change))))
|
|
42
|
+
})()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const readTextFromFile = (file, i) => {
|
|
46
|
+
if (cm.options.allowDropFileTypes &&
|
|
47
|
+
indexOf(cm.options.allowDropFileTypes, file.type) == -1) {
|
|
48
|
+
markAsReadAndPasteIfAllFilesAreRead()
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
let reader = new FileReader
|
|
52
|
+
reader.onerror = () => markAsReadAndPasteIfAllFilesAreRead()
|
|
53
|
+
reader.onload = () => {
|
|
54
|
+
let content = reader.result
|
|
55
|
+
if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) {
|
|
56
|
+
markAsReadAndPasteIfAllFilesAreRead()
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
text[i] = content
|
|
60
|
+
markAsReadAndPasteIfAllFilesAreRead()
|
|
61
|
+
}
|
|
62
|
+
reader.readAsText(file)
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < files.length; i++) readTextFromFile(files[i], i)
|
|
65
|
+
} else { // Normal drop
|
|
66
|
+
// Don't do a replace if the drop happened inside of the selected text.
|
|
67
|
+
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
|
|
68
|
+
cm.state.draggingText(e)
|
|
69
|
+
// Ensure the editor is re-focused
|
|
70
|
+
setTimeout(() => cm.display.input.focus(), 20)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
let text = e.dataTransfer.getData("Text")
|
|
75
|
+
if (text) {
|
|
76
|
+
let selected
|
|
77
|
+
if (cm.state.draggingText && !cm.state.draggingText.copy)
|
|
78
|
+
selected = cm.listSelections()
|
|
79
|
+
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos))
|
|
80
|
+
if (selected) for (let i = 0; i < selected.length; ++i)
|
|
81
|
+
replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag")
|
|
82
|
+
cm.replaceSelection(text, "around", "paste")
|
|
83
|
+
cm.display.input.focus()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch(e){}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function onDragStart(cm, e) {
|
|
91
|
+
if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
|
|
92
|
+
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return
|
|
93
|
+
|
|
94
|
+
e.dataTransfer.setData("Text", cm.getSelection())
|
|
95
|
+
e.dataTransfer.effectAllowed = "copyMove"
|
|
96
|
+
|
|
97
|
+
// Use dummy image instead of default browsers image.
|
|
98
|
+
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
|
|
99
|
+
if (e.dataTransfer.setDragImage && !safari) {
|
|
100
|
+
let img = elt("img", null, null, "position: fixed; left: 0; top: 0;")
|
|
101
|
+
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
|
|
102
|
+
if (presto) {
|
|
103
|
+
img.width = img.height = 1
|
|
104
|
+
cm.display.wrapper.appendChild(img)
|
|
105
|
+
// Force a relayout, or Opera won't use our image for some obscure reason
|
|
106
|
+
img._top = img.offsetTop
|
|
107
|
+
}
|
|
108
|
+
e.dataTransfer.setDragImage(img, 0, 0)
|
|
109
|
+
if (presto) img.parentNode.removeChild(img)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function onDragOver(cm, e) {
|
|
114
|
+
let pos = posFromMouse(cm, e)
|
|
115
|
+
if (!pos) return
|
|
116
|
+
let frag = document.createDocumentFragment()
|
|
117
|
+
drawSelectionCursor(cm, pos, frag)
|
|
118
|
+
if (!cm.display.dragCursor) {
|
|
119
|
+
cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors")
|
|
120
|
+
cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv)
|
|
121
|
+
}
|
|
122
|
+
removeChildrenAndAdd(cm.display.dragCursor, frag)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function clearDragCursor(cm) {
|
|
126
|
+
if (cm.display.dragCursor) {
|
|
127
|
+
cm.display.lineSpace.removeChild(cm.display.dragCursor)
|
|
128
|
+
cm.display.dragCursor = null
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CodeMirror } from "./CodeMirror.js"
|
|
2
|
+
import { activeElt } from "../util/dom.js"
|
|
3
|
+
import { off, on } from "../util/event.js"
|
|
4
|
+
import { copyObj } from "../util/misc.js"
|
|
5
|
+
|
|
6
|
+
export function fromTextArea(textarea, options) {
|
|
7
|
+
options = options ? copyObj(options) : {}
|
|
8
|
+
options.value = textarea.value
|
|
9
|
+
if (!options.tabindex && textarea.tabIndex)
|
|
10
|
+
options.tabindex = textarea.tabIndex
|
|
11
|
+
if (!options.placeholder && textarea.placeholder)
|
|
12
|
+
options.placeholder = textarea.placeholder
|
|
13
|
+
// Set autofocus to true if this textarea is focused, or if it has
|
|
14
|
+
// autofocus and no other element is focused.
|
|
15
|
+
if (options.autofocus == null) {
|
|
16
|
+
let hasFocus = activeElt(textarea.ownerDocument)
|
|
17
|
+
options.autofocus = hasFocus == textarea ||
|
|
18
|
+
textarea.getAttribute("autofocus") != null && hasFocus == document.body
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function save() {textarea.value = cm.getValue()}
|
|
22
|
+
|
|
23
|
+
let realSubmit
|
|
24
|
+
if (textarea.form) {
|
|
25
|
+
on(textarea.form, "submit", save)
|
|
26
|
+
// Deplorable hack to make the submit method do the right thing.
|
|
27
|
+
if (!options.leaveSubmitMethodAlone) {
|
|
28
|
+
let form = textarea.form
|
|
29
|
+
realSubmit = form.submit
|
|
30
|
+
try {
|
|
31
|
+
let wrappedSubmit = form.submit = () => {
|
|
32
|
+
save()
|
|
33
|
+
form.submit = realSubmit
|
|
34
|
+
form.submit()
|
|
35
|
+
form.submit = wrappedSubmit
|
|
36
|
+
}
|
|
37
|
+
} catch(e) {}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
options.finishInit = cm => {
|
|
42
|
+
cm.save = save
|
|
43
|
+
cm.getTextArea = () => textarea
|
|
44
|
+
cm.toTextArea = () => {
|
|
45
|
+
cm.toTextArea = isNaN // Prevent this from being ran twice
|
|
46
|
+
save()
|
|
47
|
+
textarea.parentNode.removeChild(cm.getWrapperElement())
|
|
48
|
+
textarea.style.display = ""
|
|
49
|
+
if (textarea.form) {
|
|
50
|
+
off(textarea.form, "submit", save)
|
|
51
|
+
if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function")
|
|
52
|
+
textarea.form.submit = realSubmit
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
textarea.style.display = "none"
|
|
58
|
+
let cm = CodeMirror(node => textarea.parentNode.insertBefore(node, textarea.nextSibling),
|
|
59
|
+
options)
|
|
60
|
+
return cm
|
|
61
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { onBlur } from "../display/focus.js"
|
|
2
|
+
import { on } from "../util/event.js"
|
|
3
|
+
|
|
4
|
+
// These must be handled carefully, because naively registering a
|
|
5
|
+
// handler for each editor will cause the editors to never be
|
|
6
|
+
// garbage collected.
|
|
7
|
+
|
|
8
|
+
function forEachCodeMirror(f) {
|
|
9
|
+
if (!document.getElementsByClassName) return
|
|
10
|
+
let byClass = document.getElementsByClassName("CodeMirror"), editors = []
|
|
11
|
+
for (let i = 0; i < byClass.length; i++) {
|
|
12
|
+
let cm = byClass[i].CodeMirror
|
|
13
|
+
if (cm) editors.push(cm)
|
|
14
|
+
}
|
|
15
|
+
if (editors.length) editors[0].operation(() => {
|
|
16
|
+
for (let i = 0; i < editors.length; i++) f(editors[i])
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let globalsRegistered = false
|
|
21
|
+
export function ensureGlobalHandlers() {
|
|
22
|
+
if (globalsRegistered) return
|
|
23
|
+
registerGlobalHandlers()
|
|
24
|
+
globalsRegistered = true
|
|
25
|
+
}
|
|
26
|
+
function registerGlobalHandlers() {
|
|
27
|
+
// When the window resizes, we need to refresh active editors.
|
|
28
|
+
let resizeTimer
|
|
29
|
+
on(window, "resize", () => {
|
|
30
|
+
if (resizeTimer == null) resizeTimer = setTimeout(() => {
|
|
31
|
+
resizeTimer = null
|
|
32
|
+
forEachCodeMirror(onResize)
|
|
33
|
+
}, 100)
|
|
34
|
+
})
|
|
35
|
+
// When the window loses focus, we want to show the editor as blurred
|
|
36
|
+
on(window, "blur", () => forEachCodeMirror(onBlur))
|
|
37
|
+
}
|
|
38
|
+
// Called when the window resizes
|
|
39
|
+
function onResize(cm) {
|
|
40
|
+
let d = cm.display
|
|
41
|
+
// Might be a text scaling operation, clear size caches.
|
|
42
|
+
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
|
|
43
|
+
d.scrollbarsClipped = false
|
|
44
|
+
cm.setSize()
|
|
45
|
+
}
|