ponkotsu-md-editor 0.2.17 → 0.2.19
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/markdown_editor.js +46 -18
- data/lib/ponkotsu/md/editor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8b5a1994ce4fd6b3d3a5faf5fe00ae1d92da000e91f52344a3b893ff065ad32
|
|
4
|
+
data.tar.gz: 7b4669d5747735f1af7731afcddfd0d769411783a9c70c28dd1c2a4d5562bf49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe582476d1b43583ad036a61bd7365fcd794ad36cc7ef6781cc065bf50045bb781d74ebd3ae9d771da39946ae5e09feed9a536d7bf402c4348802291e7f5c252
|
|
7
|
+
data.tar.gz: b988e6f3779623f012157f3bc439c9a1ab78224f362ded5d8d7d36eedc9a2d6d12d8d4cde553d1754ebb7d0c813431d426f7f4aaa916fb4c3be34bc1fffe9f35
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
(function() {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
// _scanOffsetCacheをローカル変数として閉じる
|
|
5
|
+
let _scanOffsetCache = new Map();
|
|
6
|
+
|
|
4
7
|
// Debounce function for delayed execution
|
|
5
8
|
function debounce(func, wait) {
|
|
6
9
|
let timeout;
|
|
@@ -63,6 +66,48 @@
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function scanOffset(pos) {
|
|
72
|
+
// キャッシュ取得
|
|
73
|
+
if (_scanOffsetCache.has(pos)) {
|
|
74
|
+
return _scanOffsetCache.get(pos);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// HTML全体を一度だけ取得(これは良い改善)
|
|
78
|
+
const fullHTML = textarea.innerHTML;
|
|
79
|
+
const fullText = textarea.innerText;
|
|
80
|
+
|
|
81
|
+
let offset = pos;
|
|
82
|
+
let lastAdded = -1;
|
|
83
|
+
let iterations = 0;
|
|
84
|
+
const MAX_ITERATIONS = 100; // より安全な上限
|
|
85
|
+
|
|
86
|
+
while (iterations < MAX_ITERATIONS) {
|
|
87
|
+
const htmlUpTo = fullHTML.substring(0, offset);
|
|
88
|
+
const textUpTo = fullText.substring(0, offset);
|
|
89
|
+
|
|
90
|
+
// 元の正規表現を維持(安全性優先)
|
|
91
|
+
const brCount = (htmlUpTo.match(/<br\s*\/?>(?![\w\W]*<)/g) || []).length;
|
|
92
|
+
const nlCount = (textUpTo.match(/\n/g) || []).length;
|
|
93
|
+
|
|
94
|
+
const added = brCount + nlCount;
|
|
95
|
+
if (added === lastAdded) break;
|
|
96
|
+
|
|
97
|
+
offset = pos + added;
|
|
98
|
+
lastAdded = added;
|
|
99
|
+
iterations++;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (iterations >= MAX_ITERATIONS) {
|
|
103
|
+
console.warn('scanOffset: Maximum iterations reached, possible infinite loop');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 結果をキャッシュ
|
|
107
|
+
_scanOffsetCache.set(pos, offset);
|
|
108
|
+
return offset;
|
|
109
|
+
}
|
|
110
|
+
|
|
66
111
|
onReady(function() {
|
|
67
112
|
console.log('Enhanced Markdown editor initializing...');
|
|
68
113
|
|
|
@@ -98,23 +143,6 @@
|
|
|
98
143
|
beforeEndRange.selectNodeContents(textarea);
|
|
99
144
|
beforeEndRange.setEnd(range.endContainer, range.endOffset);
|
|
100
145
|
let endPos = beforeEndRange.toString().length;
|
|
101
|
-
|
|
102
|
-
// --- 再スキャンで<br>と改行の取りこぼしを防ぐ ---
|
|
103
|
-
function scanOffset(pos) {
|
|
104
|
-
let offset = pos;
|
|
105
|
-
let lastAdded = -1;
|
|
106
|
-
while (true) {
|
|
107
|
-
const htmlUpTo = textarea.innerHTML.substring(0, offset);
|
|
108
|
-
const brCount = (htmlUpTo.match(/<br\s*\/?>(?![\w\W]*<)/g) || []).length;
|
|
109
|
-
const textUpTo = textarea.innerText.substring(0, offset);
|
|
110
|
-
const nlCount = (textUpTo.match(/\n/g) || []).length;
|
|
111
|
-
const added = brCount + nlCount;
|
|
112
|
-
if (added === lastAdded) break;
|
|
113
|
-
offset = pos + added;
|
|
114
|
-
lastAdded = added;
|
|
115
|
-
}
|
|
116
|
-
return offset;
|
|
117
|
-
}
|
|
118
146
|
startPos = scanOffset(startPos);
|
|
119
147
|
endPos = scanOffset(endPos);
|
|
120
148
|
// -----------------------------------
|
|
@@ -1361,7 +1389,7 @@
|
|
|
1361
1389
|
if (isContentEditable) {
|
|
1362
1390
|
const selection = getContentEditableSelection(activeElement);
|
|
1363
1391
|
selectedText = selection.selectedText;
|
|
1364
|
-
} else
|
|
1392
|
+
} else {
|
|
1365
1393
|
selectedText = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
|
|
1366
1394
|
}
|
|
1367
1395
|
|