ponkotsu-md-editor 0.2.29 → 0.2.31
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 +37 -7
- 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: 70ff9aaac80a4c741fdfb7f023e8e628efbefe1d366f12cca49c5c97f95cff04
|
|
4
|
+
data.tar.gz: 89460818c643cba7b1b794abcb66e253591a4a81a09b4f0205892d6e3239a1fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3e26778bfa1044b111e6570130aaf3c513e50b95d727a051616382aa00ab2a67a6a7eeb6b8dfdbcd3e3c18c17b212670498d3c33a2fd461e82e72f5c04013c5
|
|
7
|
+
data.tar.gz: c695be9e488bcb184a7137683b3ca0d266598b8853ca4840eca44051f92645ec2552ad17c944a921c35b42b7541905da382ff6281e6f09b6385e326c22fbda07
|
|
@@ -121,8 +121,6 @@
|
|
|
121
121
|
hiddenField.value = (textarea.innerText || '').replaceAll('\u00A0', ' ');
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
textarea.addEventListener('blur', syncToHidden);
|
|
125
|
-
|
|
126
124
|
// 初期化時に同期
|
|
127
125
|
syncToHidden();
|
|
128
126
|
|
|
@@ -167,6 +165,10 @@
|
|
|
167
165
|
|
|
168
166
|
|
|
169
167
|
|
|
168
|
+
// 正規表現を事前にコンパイル(関数外で1回のみ)
|
|
169
|
+
const BR_REGEX = /<br\s*\/?>/gi;
|
|
170
|
+
const NEWLINE_REGEX = /\n/g;
|
|
171
|
+
|
|
170
172
|
function scanOffset(pos) {
|
|
171
173
|
// キャッシュ取得
|
|
172
174
|
if (_scanOffsetCache.has(pos)) {
|
|
@@ -174,25 +176,53 @@
|
|
|
174
176
|
}
|
|
175
177
|
|
|
176
178
|
const textarea = document.getElementById('editor_content');
|
|
179
|
+
if (!textarea) {
|
|
180
|
+
return pos;
|
|
181
|
+
}
|
|
177
182
|
|
|
178
|
-
// HTML
|
|
183
|
+
// HTML全体を一度だけ取得
|
|
179
184
|
const fullHTML = textarea.innerHTML;
|
|
180
185
|
const fullText = textarea.innerText;
|
|
181
186
|
|
|
187
|
+
// 早期リターン:HTMLが空の場合
|
|
188
|
+
if (!fullHTML || !fullText) {
|
|
189
|
+
_scanOffsetCache.set(pos, pos);
|
|
190
|
+
return pos;
|
|
191
|
+
}
|
|
192
|
+
|
|
182
193
|
let offset = pos;
|
|
183
194
|
let lastAdded = -1;
|
|
184
195
|
let iterations = 0;
|
|
185
|
-
const MAX_ITERATIONS = 100;
|
|
196
|
+
const MAX_ITERATIONS = 100;
|
|
186
197
|
|
|
187
198
|
while (iterations < MAX_ITERATIONS) {
|
|
199
|
+
// 部分文字列を一度だけ作成
|
|
188
200
|
const htmlUpTo = fullHTML.substring(0, offset);
|
|
189
201
|
const textUpTo = fullText.substring(0, offset);
|
|
190
202
|
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
// 正規表現のグローバルフラグをリセットして使用
|
|
204
|
+
BR_REGEX.lastIndex = 0;
|
|
205
|
+
NEWLINE_REGEX.lastIndex = 0;
|
|
206
|
+
|
|
207
|
+
// マッチをカウント(より効率的な方法)
|
|
208
|
+
let brCount = 0;
|
|
209
|
+
let nlCount = 0;
|
|
210
|
+
|
|
211
|
+
// brタグのカウント
|
|
212
|
+
let brMatch;
|
|
213
|
+
while ((brMatch = BR_REGEX.exec(htmlUpTo)) !== null) {
|
|
214
|
+
brCount++;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 改行のカウント
|
|
218
|
+
let nlMatch;
|
|
219
|
+
while ((nlMatch = NEWLINE_REGEX.exec(textUpTo)) !== null) {
|
|
220
|
+
nlCount++;
|
|
221
|
+
}
|
|
194
222
|
|
|
195
223
|
const added = brCount + nlCount;
|
|
224
|
+
|
|
225
|
+
// 変化がなければ終了
|
|
196
226
|
if (added === lastAdded) break;
|
|
197
227
|
|
|
198
228
|
offset = pos + added;
|