ponkotsu-md-editor 0.2.30 → 0.2.32
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b276d684730d179d1db2e788a37687db583b3257a073b48a9acaf6e2d4f5394
|
|
4
|
+
data.tar.gz: 77d2db0430ffe4e4d5f0fa086b7852d010b55d948af6e239f58c75edf44306de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fcdf631c47e69110531971546ba898ee459619162ddfe0033e1915f24b1e33099bfca9d63207442e4f1cfed5a8c31a5d0ae291e717d12c9156709280b57e57ea
|
|
7
|
+
data.tar.gz: 010aebf4daf0eea2e49cd28a29de89471e7f8c07b18827d086087fcd84bb8a4c009092f1a5c5c2c8e809dc03d1ef70b0f893cd50013f935da5cdf2d08a16303f
|
|
@@ -165,6 +165,10 @@
|
|
|
165
165
|
|
|
166
166
|
|
|
167
167
|
|
|
168
|
+
// 正規表現を事前にコンパイル(関数外で1回のみ)
|
|
169
|
+
const BR_REGEX = /<br\s*\/?>/gi;
|
|
170
|
+
const NEWLINE_REGEX = /\n/g;
|
|
171
|
+
|
|
168
172
|
function scanOffset(pos) {
|
|
169
173
|
// キャッシュ取得
|
|
170
174
|
if (_scanOffsetCache.has(pos)) {
|
|
@@ -172,25 +176,53 @@
|
|
|
172
176
|
}
|
|
173
177
|
|
|
174
178
|
const textarea = document.getElementById('editor_content');
|
|
179
|
+
if (!textarea) {
|
|
180
|
+
return pos;
|
|
181
|
+
}
|
|
175
182
|
|
|
176
|
-
// HTML
|
|
183
|
+
// HTML全体を一度だけ取得
|
|
177
184
|
const fullHTML = textarea.innerHTML;
|
|
178
185
|
const fullText = textarea.innerText;
|
|
179
186
|
|
|
187
|
+
// 早期リターン:HTMLが空の場合
|
|
188
|
+
if (!fullHTML || !fullText) {
|
|
189
|
+
_scanOffsetCache.set(pos, pos);
|
|
190
|
+
return pos;
|
|
191
|
+
}
|
|
192
|
+
|
|
180
193
|
let offset = pos;
|
|
181
194
|
let lastAdded = -1;
|
|
182
195
|
let iterations = 0;
|
|
183
|
-
const MAX_ITERATIONS = 100;
|
|
196
|
+
const MAX_ITERATIONS = 100;
|
|
184
197
|
|
|
185
198
|
while (iterations < MAX_ITERATIONS) {
|
|
199
|
+
// 部分文字列を一度だけ作成
|
|
186
200
|
const htmlUpTo = fullHTML.substring(0, offset);
|
|
187
201
|
const textUpTo = fullText.substring(0, offset);
|
|
188
202
|
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
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
|
+
}
|
|
192
222
|
|
|
193
223
|
const added = brCount + nlCount;
|
|
224
|
+
|
|
225
|
+
// 変化がなければ終了
|
|
194
226
|
if (added === lastAdded) break;
|
|
195
227
|
|
|
196
228
|
offset = pos + added;
|
|
@@ -7,7 +7,13 @@
|
|
|
7
7
|
<div id="editor_content"
|
|
8
8
|
contenteditable="true"
|
|
9
9
|
data-field="content"
|
|
10
|
-
class="ponkotsu-md-editor-form-control ponkotsu-md-editor-markdown-textarea"
|
|
10
|
+
class="ponkotsu-md-editor-form-control ponkotsu-md-editor-markdown-textarea"
|
|
11
|
+
translate="no"
|
|
12
|
+
data-notranslate="true"
|
|
13
|
+
data-gramm="false"
|
|
14
|
+
data-gramm_editor="false"
|
|
15
|
+
data-enable-grammarly="false"
|
|
16
|
+
spellcheck="false">
|
|
11
17
|
<%
|
|
12
18
|
def crlf_to_br(text)
|
|
13
19
|
text.gsub(/\r\n|\r|\n/, "<br>").html_safe
|
|
@@ -16,7 +22,9 @@
|
|
|
16
22
|
<%= crlf_to_br(h(locals[:content])) %>
|
|
17
23
|
</div>
|
|
18
24
|
|
|
19
|
-
<div id="editor_content_placeholder"
|
|
25
|
+
<div id="editor_content_placeholder"
|
|
26
|
+
translate="no"
|
|
27
|
+
data-notranslate="true">
|
|
20
28
|
<%= _placeholder %>
|
|
21
29
|
</div>
|
|
22
30
|
|