ponkotsu-md-editor 0.1.32 → 0.1.34
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 +52 -17
- 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: 7eecce4eaa3fa335351b001fa799cce67dd9e4e0af7ec5f0ea71a30faa6aab3b
|
|
4
|
+
data.tar.gz: a6c888c21cb85a1a9dbc38757549f333488d269fd9e908777056de1eef64eaa4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f2f6e162c7a2a0a9e5824b0d6b629723e47a361a892e31ab86a9ed4178377c1d587fdd5165348cf26a38ab558c35ca7f4ebd79e9d4ede7dd8d04a5083bbf7b69
|
|
7
|
+
data.tar.gz: 2a8afd5b6c514318d5f2059742aadb5771d40e46d67d1490bc6c7fa4d2f2edb24464995300ddb7960a929b32d6f2fffb0a72c22f4c9924ce1ead5fdb68c2a898
|
|
@@ -283,36 +283,71 @@
|
|
|
283
283
|
selectedText = textarea.value.substring(start, end);
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
// fullTextの定義をここで行う
|
|
287
|
+
const fullText = isContentEditable ?
|
|
288
|
+
(textarea.innerText || textarea.textContent || '') :
|
|
289
|
+
textarea.value;
|
|
290
|
+
|
|
286
291
|
// Bold(**)の場合のみ、選択範囲の両端に余分な空白・改行があれば除外
|
|
287
292
|
if (before === '**' && after === '**' && selectedText.length > 0) {
|
|
288
293
|
let left = 0;
|
|
289
294
|
let right = selectedText.length;
|
|
290
|
-
//
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
// 先頭: 連続する「改行+スペース」をすべて除去
|
|
296
|
+
while (true) {
|
|
297
|
+
if (selectedText.startsWith('\n ')) {
|
|
298
|
+
left += 2;
|
|
299
|
+
selectedText = selectedText.substring(2);
|
|
300
|
+
} else if (selectedText.startsWith('\n')) {
|
|
301
|
+
left += 1;
|
|
302
|
+
selectedText = selectedText.substring(1);
|
|
303
|
+
} else if (selectedText.startsWith(' ')) {
|
|
304
|
+
// 直前が改行なら除去
|
|
305
|
+
if (start + left > 0 && fullText[start + left - 1] === '\n') {
|
|
306
|
+
left += 1;
|
|
307
|
+
selectedText = selectedText.substring(1);
|
|
308
|
+
} else {
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
295
314
|
}
|
|
296
|
-
//
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
315
|
+
// 末尾: 連続する「スペース+改行」をすべて除去
|
|
316
|
+
while (true) {
|
|
317
|
+
if (selectedText.endsWith(' \n')) {
|
|
318
|
+
right -= 2;
|
|
319
|
+
selectedText = selectedText.substring(0, selectedText.length - 2);
|
|
320
|
+
} else if (selectedText.endsWith('\n')) {
|
|
321
|
+
right -= 1;
|
|
322
|
+
selectedText = selectedText.substring(0, selectedText.length - 1);
|
|
323
|
+
} else if (selectedText.endsWith(' ')) {
|
|
324
|
+
// 直後が改行なら除去
|
|
325
|
+
if (end - (selectedText.length - right) < fullText.length && fullText[end - (selectedText.length - right)] === '\n') {
|
|
326
|
+
right -= 1;
|
|
327
|
+
selectedText = selectedText.substring(0, selectedText.length - 1);
|
|
328
|
+
} else {
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
301
334
|
}
|
|
302
335
|
// 既存の両端trimも併用(ただしスペース・改行のみ)
|
|
303
|
-
while (left < right && /[\s\n]/.test(selectedText[
|
|
304
|
-
|
|
336
|
+
while (left < right && /[\s\n]/.test(selectedText[0])) {
|
|
337
|
+
left++;
|
|
338
|
+
selectedText = selectedText.substring(1);
|
|
339
|
+
}
|
|
340
|
+
while (right > left && /[\s\n]/.test(selectedText[selectedText.length-1])) {
|
|
341
|
+
right--;
|
|
342
|
+
selectedText = selectedText.substring(0, selectedText.length-1);
|
|
343
|
+
}
|
|
305
344
|
if (left !== 0 || right !== selectedText.length) {
|
|
306
345
|
start += left;
|
|
307
346
|
end -= (selectedText.length - right);
|
|
308
|
-
|
|
347
|
+
// selectedTextはすでにtrim済み
|
|
309
348
|
}
|
|
310
349
|
}
|
|
311
350
|
|
|
312
|
-
const fullText = isContentEditable ?
|
|
313
|
-
(textarea.innerText || textarea.textContent || '') :
|
|
314
|
-
textarea.value;
|
|
315
|
-
|
|
316
351
|
const beforeText = fullText.substring(0, start);
|
|
317
352
|
const afterText = fullText.substring(end);
|
|
318
353
|
const newText = before + selectedText + after;
|