ponkotsu-md-editor 0.2.17 → 0.2.18
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 +28 -4
- 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: 0cee3f1cda79e611392ecd15c3f373a0e65de3ae4895c875878c47108a265ab8
|
|
4
|
+
data.tar.gz: 194fb5f55df7e26a535a1209303e0316bc3d107f1635a1ec077782ea77c6b451
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 313668a4f9c9d78b212ee0c28413f0854fa1e4656137bb2b6f2397b201e131f3e413536f786daf2c00acba0719108b1c5b4ce296017367fab3c26b30b4431340
|
|
7
|
+
data.tar.gz: 166ddd5ecd7ad645305069a5c3649e5b949ae82eaacf99eef700a187f8a56c8195f5dbdce668d7897733acb3047d18968a1b3d29dd04d860346a93f4ab60ae58
|
|
@@ -99,20 +99,44 @@
|
|
|
99
99
|
beforeEndRange.setEnd(range.endContainer, range.endOffset);
|
|
100
100
|
let endPos = beforeEndRange.toString().length;
|
|
101
101
|
|
|
102
|
-
// --- 再スキャンで<br>と改行の取りこぼしを防ぐ ---
|
|
103
102
|
function scanOffset(pos) {
|
|
103
|
+
// キャッシュを追加
|
|
104
|
+
if (this._scanOffsetCache && this._scanOffsetCache.pos === pos) {
|
|
105
|
+
return this._scanOffsetCache.result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// HTML全体を一度だけ取得(これは良い改善)
|
|
109
|
+
const fullHTML = textarea.innerHTML;
|
|
110
|
+
const fullText = textarea.innerText;
|
|
111
|
+
|
|
104
112
|
let offset = pos;
|
|
105
113
|
let lastAdded = -1;
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
let iterations = 0;
|
|
115
|
+
const MAX_ITERATIONS = 100; // より安全な上限
|
|
116
|
+
|
|
117
|
+
while (iterations < MAX_ITERATIONS) {
|
|
118
|
+
const htmlUpTo = fullHTML.substring(0, offset);
|
|
119
|
+
const textUpTo = fullText.substring(0, offset);
|
|
120
|
+
|
|
121
|
+
// 元の正規表現を維持(安全性優先)
|
|
108
122
|
const brCount = (htmlUpTo.match(/<br\s*\/?>(?![\w\W]*<)/g) || []).length;
|
|
109
|
-
const textUpTo = textarea.innerText.substring(0, offset);
|
|
110
123
|
const nlCount = (textUpTo.match(/\n/g) || []).length;
|
|
124
|
+
|
|
111
125
|
const added = brCount + nlCount;
|
|
112
126
|
if (added === lastAdded) break;
|
|
127
|
+
|
|
113
128
|
offset = pos + added;
|
|
114
129
|
lastAdded = added;
|
|
130
|
+
iterations++;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (iterations >= MAX_ITERATIONS) {
|
|
134
|
+
console.warn('scanOffset: Maximum iterations reached, possible infinite loop');
|
|
115
135
|
}
|
|
136
|
+
|
|
137
|
+
// 結果をキャッシュ
|
|
138
|
+
this._scanOffsetCache = { pos: pos, result: offset };
|
|
139
|
+
|
|
116
140
|
return offset;
|
|
117
141
|
}
|
|
118
142
|
startPos = scanOffset(startPos);
|