ponkotsu-md-editor 0.1.35 → 0.1.37

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: 4980227e465c0b9cbe726b29b66a097d0c0c3f5fde58c81991d79a63270ec198
4
- data.tar.gz: 140fbb1b0d7c33389c6d0f093576b05609da5767a07141e416c79a71647ba173
3
+ metadata.gz: 636ded655ab01cbfaca8f174d1fbac9746b8034a25629ad3aeb99b09b1b2c78b
4
+ data.tar.gz: db6cf97fcc700103909a41d0dae0f30cd183a873d725e889f808145ef008a44e
5
5
  SHA512:
6
- metadata.gz: 7f90bb7fb877b1163ab1834fca217b9ce0868a39d220156bfdab227141f03872a217956bb3b2784b48e30f893fa2587f4a697ddb5686f035900f8c50074789de
7
- data.tar.gz: e38e4a4e78ce2a40c908cf3863284b6bf5508c4e5188948405f7651c5e7e67ed6a133355146b8c7eb5310bd1e5a462270b6a87a45d247f6433014c92e8b88f73
6
+ metadata.gz: 543de8b6a2c243dafec155dcc7545a90199688e4b9bb2bb791fb5f1034bb259d84db1196e1d8396eb1bba947148159eeb71ba98d0e76302ec80ab65b6f2167d8
7
+ data.tar.gz: ae549ef1b9a8e82d2c2f7392a162e551f84a6a7933aba695b2d343024ffea33baf56dccbc9a755676bb2d9ad7636bc25917bb188597950a515d5b3a61243199a
@@ -131,6 +131,8 @@
131
131
  selectedText: fullText.substring(startPos, endPos)
132
132
  };
133
133
  }
134
+ // 外部公開
135
+ window.getContentEditableSelection = getContentEditableSelection;
134
136
 
135
137
  // Set selection range at specified position (precision enhanced version)
136
138
  function setContentEditableSelection(element, start, end) {
@@ -290,35 +292,12 @@
290
292
 
291
293
  // Bold(**)の場合のみ、選択範囲の両端に余分な空白・改行・文末記号があれば除外
292
294
  if (before === '**' && after === '**' && selectedText.length > 0) {
293
- let left = 0;
294
- let right = selectedText.length;
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);
295
+ // 両端の「改行・空白・文末記号」をすべて除去(複数連続も対応)
296
+ while (/^[\s\n.,;:!?]+/.test(selectedText)) {
297
+ selectedText = selectedText.replace(/^[\s\n.,;:!?]+/, '');
301
298
  }
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);
308
- }
309
- // 既存の両端trimも併用(ただしスペース・改行のみ)
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
- }
318
- if (left !== 0 || right !== selectedText.length) {
319
- start += left;
320
- end -= (selectedText.length - right);
321
- // selectedTextはすでにtrim済み
299
+ while (/[\s\n.,;:!?]+$/.test(selectedText)) {
300
+ selectedText = selectedText.replace(/[\s\n.,;:!?]+$/, '');
322
301
  }
323
302
  }
324
303
 
@@ -1461,4 +1440,28 @@
1461
1440
  }
1462
1441
  });
1463
1442
 
1443
+ // === テスト用関数群 ===
1444
+ // 1. 選択範囲検出
1445
+ window.testGetSelection = function(element) {
1446
+ return getContentEditableSelection(element);
1447
+ };
1448
+
1449
+ // 2. Boldデコレーション(両端trim含む)
1450
+ window.testDecorateBold = function(text) {
1451
+ // 両端の「改行・空白・文末記号」をすべて除去(複数連続も対応)
1452
+ let trimmed = text;
1453
+ while (/^[\s\n.,;:!?]+/.test(trimmed)) {
1454
+ trimmed = trimmed.replace(/^[\s\n.,;:!?]+/, '');
1455
+ }
1456
+ while (/[\s\n.,;:!?]+$/.test(trimmed)) {
1457
+ trimmed = trimmed.replace(/[\s\n.,;:!?]+$/, '');
1458
+ }
1459
+ return `**${trimmed}**`;
1460
+ };
1461
+
1462
+ // 3. テキスト上書き
1463
+ window.testReplaceTextAtRange = function(fullText, start, end, decoratedText) {
1464
+ return fullText.substring(0, start) + decoratedText + fullText.substring(end);
1465
+ };
1466
+
1464
1467
  })();
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PonkotsuMdEditor
4
- VERSION = "0.1.35"
4
+ VERSION = "0.1.37"
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.35
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler