ponkotsu-md-editor 0.2.18 → 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 -42
- 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,47 +143,6 @@
|
|
|
98
143
|
beforeEndRange.selectNodeContents(textarea);
|
|
99
144
|
beforeEndRange.setEnd(range.endContainer, range.endOffset);
|
|
100
145
|
let endPos = beforeEndRange.toString().length;
|
|
101
|
-
|
|
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
|
-
|
|
112
|
-
let offset = pos;
|
|
113
|
-
let lastAdded = -1;
|
|
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
|
-
// 元の正規表現を維持(安全性優先)
|
|
122
|
-
const brCount = (htmlUpTo.match(/<br\s*\/?>(?![\w\W]*<)/g) || []).length;
|
|
123
|
-
const nlCount = (textUpTo.match(/\n/g) || []).length;
|
|
124
|
-
|
|
125
|
-
const added = brCount + nlCount;
|
|
126
|
-
if (added === lastAdded) break;
|
|
127
|
-
|
|
128
|
-
offset = pos + added;
|
|
129
|
-
lastAdded = added;
|
|
130
|
-
iterations++;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (iterations >= MAX_ITERATIONS) {
|
|
134
|
-
console.warn('scanOffset: Maximum iterations reached, possible infinite loop');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 結果をキャッシュ
|
|
138
|
-
this._scanOffsetCache = { pos: pos, result: offset };
|
|
139
|
-
|
|
140
|
-
return offset;
|
|
141
|
-
}
|
|
142
146
|
startPos = scanOffset(startPos);
|
|
143
147
|
endPos = scanOffset(endPos);
|
|
144
148
|
// -----------------------------------
|
|
@@ -1385,7 +1389,7 @@
|
|
|
1385
1389
|
if (isContentEditable) {
|
|
1386
1390
|
const selection = getContentEditableSelection(activeElement);
|
|
1387
1391
|
selectedText = selection.selectedText;
|
|
1388
|
-
} else
|
|
1392
|
+
} else {
|
|
1389
1393
|
selectedText = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
|
|
1390
1394
|
}
|
|
1391
1395
|
|