Skip to content

Commit 1f0d5c8

Browse files
authored
Retain cursor position after reformatting (#1399)
* Restore cursor position based on old coordinates. * Add source code for jsdiff and include it on the page * Compute new line position after formatting based on text diffing. * Compute new character position after formatting based on text diffing. * Use diffChars() to recompute both line and column. * Restore scroll position. * Slight refactor. * Use getDoc() to extract document instance. * Compute cursor coordinates relative to the top-left corner of the editable document.
1 parent e6fa062 commit 1f0d5c8

File tree

6 files changed

+127
-15
lines changed

6 files changed

+127
-15
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ dist-*
2525
*.swp
2626
.stack-work
2727
stack.yaml.lock
28-
cabal.project.local
28+
cabal.project.local
29+
.DS_Store

third_party/jsdiff/LICENSE

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Software License Agreement (BSD License)
2+
3+
Copyright (c) 2009-2015, Kevin Decker <[email protected]>
4+
5+
All rights reserved.
6+
7+
Redistribution and use of this software in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above
11+
copyright notice, this list of conditions and the
12+
following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above
15+
copyright notice, this list of conditions and the
16+
following disclaimer in the documentation and/or other
17+
materials provided with the distribution.
18+
19+
* Neither the name of Kevin Decker nor the names of its
20+
contributors may be used to endorse or promote products
21+
derived from this software without specific prior
22+
written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
25+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
26+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31+
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

third_party/jsdiff/diff.min.js

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/env.html

+1
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,6 @@
245245
type="text/javascript"
246246
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/promise.min.js"
247247
></script>
248+
<script async src="js/diff.min.js"></script>
248249
</body>
249250
</html>

0 commit comments

Comments
 (0)