ponkotsu-md-editor 0.1.33 → 0.1.35

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: d5308ca931db5e89ef46fcb13e678810f7ef70eb8c2ea39a477e14c7b59227c2
4
- data.tar.gz: fe350b9f9fc51ab3d8966acc154e2030e90bb6b5d8eedc3217b49e8c3ab4580e
3
+ metadata.gz: 4980227e465c0b9cbe726b29b66a097d0c0c3f5fde58c81991d79a63270ec198
4
+ data.tar.gz: 140fbb1b0d7c33389c6d0f093576b05609da5767a07141e416c79a71647ba173
5
5
  SHA512:
6
- metadata.gz: 0db560c9499193088fac29e68d02efb2ac7e8817937f9bdd26002ddd92ced574f2159242d76464d9c1c206f085d7e6ddc261cd058ff9d9eb1aec02032732c87d
7
- data.tar.gz: a17834cfe00ba978d18ba4381d05c4ff85cde27f4a6b172d171018aee1bc508418f3abe2b05ab0499b5935dc288ed517a4612d070f73573ddebd41738e2a480e
6
+ metadata.gz: 7f90bb7fb877b1163ab1834fca217b9ce0868a39d220156bfdab227141f03872a217956bb3b2784b48e30f893fa2587f4a697ddb5686f035900f8c50074789de
7
+ data.tar.gz: e38e4a4e78ce2a40c908cf3863284b6bf5508c4e5188948405f7651c5e7e67ed6a133355146b8c7eb5310bd1e5a462270b6a87a45d247f6433014c92e8b88f73
@@ -288,29 +288,37 @@
288
288
  (textarea.innerText || textarea.textContent || '') :
289
289
  textarea.value;
290
290
 
291
- // Bold(**)の場合のみ、選択範囲の両端に余分な空白・改行があれば除外
291
+ // Bold(**)の場合のみ、選択範囲の両端に余分な空白・改行・文末記号があれば除外
292
292
  if (before === '**' && after === '**' && selectedText.length > 0) {
293
293
  let left = 0;
294
294
  let right = selectedText.length;
295
- // 先頭が「\n 」ならスペース除去
296
- if (selectedText.startsWith('\n ')) {
297
- left += 2;
298
- } else if (selectedText[0] === ' ' && (start > 0 && fullText[start-1] === '\n')) {
299
- left += 1;
295
+ // 先頭: 連続する「改行・空白・文末記号」をすべて除去
296
+ const leadingPattern = /^[\s\n.,;:!?]+/;
297
+ const matchLeading = selectedText.match(leadingPattern);
298
+ if (matchLeading) {
299
+ left += matchLeading[0].length;
300
+ selectedText = selectedText.substring(matchLeading[0].length);
300
301
  }
301
- // 末尾が「 \n」ならスペース除去
302
- if (selectedText.endsWith(' \n')) {
303
- right -= 2;
304
- } else if (selectedText[selectedText.length-1] === ' ' && (end < fullText.length && fullText[end] === '\n')) {
305
- right -= 1;
302
+ // 末尾: 連続する「改行・空白・文末記号」をすべて除去
303
+ const trailingPattern = /[\s\n.,;:!?]+$/;
304
+ const matchTrailing = selectedText.match(trailingPattern);
305
+ if (matchTrailing) {
306
+ right -= matchTrailing[0].length;
307
+ selectedText = selectedText.substring(0, selectedText.length - matchTrailing[0].length);
306
308
  }
307
309
  // 既存の両端trimも併用(ただしスペース・改行のみ)
308
- while (left < right && /[\s\n]/.test(selectedText[left])) left++;
309
- while (right > left && /[\s\n]/.test(selectedText[right-1])) right--;
310
+ while (left < right && /[\s\n]/.test(selectedText[0])) {
311
+ left++;
312
+ selectedText = selectedText.substring(1);
313
+ }
314
+ while (right > left && /[\s\n]/.test(selectedText[selectedText.length-1])) {
315
+ right--;
316
+ selectedText = selectedText.substring(0, selectedText.length-1);
317
+ }
310
318
  if (left !== 0 || right !== selectedText.length) {
311
319
  start += left;
312
320
  end -= (selectedText.length - right);
313
- selectedText = selectedText.substring(left, right);
321
+ // selectedTextはすでにtrim済み
314
322
  }
315
323
  }
316
324
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PonkotsuMdEditor
4
- VERSION = "0.1.33"
4
+ VERSION = "0.1.35"
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.1.33
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler