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: 91415e80a85a2d898fcedacaecdab8f0c7bc0318f70116639e8f876be4923703
4
- data.tar.gz: 3869fdf6b809a201dc03453c19255504a6ae77dcabc1675587ea07739a182e94
3
+ metadata.gz: 3b276d684730d179d1db2e788a37687db583b3257a073b48a9acaf6e2d4f5394
4
+ data.tar.gz: 77d2db0430ffe4e4d5f0fa086b7852d010b55d948af6e239f58c75edf44306de
5
5
  SHA512:
6
- metadata.gz: e7395d5c820e5ef6a5aac7c42813453a638adae579980c921cd7c95681d5158a04efd97ec760b3c32ae8595271214a882768a8915b385eafdf8f32a3acc4e21e
7
- data.tar.gz: 451c5dd0f0b3b3dfa97cc927c2b43b769deae7a98b2dedc38b9f833519ff67502f9f4f4ec09882c13dfd366eb080d4b2313538a3f03a4e1c207e5dee04863d8d
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
- const brCount = (htmlUpTo.match(/<br\s*\/?>(?![\w\W]*<)/g) || []).length;
191
- const nlCount = (textUpTo.match(/\n/g) || []).length;
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PonkotsuMdEditor
4
- VERSION = "0.2.30"
4
+ VERSION = "0.2.32"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ponkotsu-md-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.30
4
+ version: 0.2.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler