• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cofacts / rumors-site / 16731445289

30 Jul 2025 05:13PM UTC coverage: 67.972% (-2.5%) from 70.432%
16731445289

push

github

MrOrz
Merge branch 'henrysmile2071-feat/editor-bulletpoint' (pull request #609)

397 of 715 branches covered (55.52%)

Branch coverage included in aggregate %.

1 of 47 new or added lines in 1 file covered. (2.13%)

957 of 1277 relevant lines covered (74.94%)

11.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.89
/lib/editor.js
1
export const LIST_STYLES = {
1✔
2
  BULLETED: 'BULLETED',
3
  NUMBERED: 'NUMBERED',
4
};
5

6
export function addListStyle(
7
  { value = '', selectionStart = 0, selectionEnd = 0 },
×
8
  style
9
) {
10
  switch (style) {
7✔
11
    case LIST_STYLES.BULLETED: {
12
      const newValue =
13
        value.slice(0, selectionStart) + '- ' + value.slice(selectionStart);
2✔
14
      const newPos = selectionStart + 2;
2✔
15
      return { value: newValue, selectionStart: newPos, selectionEnd: newPos };
2✔
16
    }
17
    case LIST_STYLES.NUMBERED: {
18
      const lines = value.slice(0, selectionStart).split('\n');
4✔
19
      const lastLine = lines[lines.length - 2] || '0.';
4!
20
      const lastNum = ~~lastLine.match(/^(\d+)\.\s.*/)?.[1];
4✔
21
      const current = lastNum + 1;
4✔
22
      const newValue =
23
        value.slice(0, selectionStart) +
4✔
24
        `${current}. ` +
25
        value.slice(selectionStart);
26
      const newPos = selectionStart + 1 + (current + '0').length;
4✔
27
      return { value: newValue, selectionStart: newPos, selectionEnd: newPos };
4✔
28
    }
29
    default:
30
      return { value, selectionStart, selectionEnd };
1✔
31
  }
32
}
33

34
export function replaceListPrefixAtCursorLine(
35
  { value = '', selectionStart = 0, selectionEnd = 0 },
×
36
  style
37
) {
NEW
38
  const lines = value.split('\n');
×
NEW
39
  let charCount = 0;
×
NEW
40
  let targetLineIndex = 0;
×
41

42
  // Find the current line
NEW
43
  for (let i = 0; i < lines.length; i++) {
×
NEW
44
    const lineLength = lines[i].length + 1; // +1 for \n
×
NEW
45
    if (selectionStart < charCount + lineLength) {
×
NEW
46
      targetLineIndex = i;
×
NEW
47
      break;
×
48
    }
NEW
49
    charCount += lineLength;
×
50
  }
51

NEW
52
  const line = lines[targetLineIndex];
×
53

54
  // Match and remove existing list prefix
NEW
55
  const match = line.match(/^(\s*)(-|\*|\d+\.)\s+/);
×
NEW
56
  let oldPrefixLength = 0;
×
NEW
57
  let newLine = line;
×
58

NEW
59
  if (match) {
×
NEW
60
    oldPrefixLength = match[0].length;
×
NEW
61
    newLine = line.slice(oldPrefixLength);
×
62
  }
63

64
  // Add new prefix if provided
NEW
65
  let newPrefix = '';
×
NEW
66
  switch (style) {
×
67
    case LIST_STYLES.BULLETED: {
NEW
68
      newPrefix = '- ';
×
NEW
69
      break;
×
70
    }
71
    case LIST_STYLES.NUMBERED: {
NEW
72
      const lines = value.slice(0, selectionStart).split('\n');
×
NEW
73
      const lastLine = lines[lines.length - 2] || '0.';
×
NEW
74
      const lastNum = ~~lastLine.match(/^(\d+)\.\s.*/)?.[1];
×
NEW
75
      const current = lastNum + 1;
×
NEW
76
      newPrefix = `${current}. `;
×
NEW
77
      break;
×
78
    }
79
  }
NEW
80
  lines[targetLineIndex] = newPrefix + newLine;
×
81

82
  // Calculate adjustment in character length
NEW
83
  const lineStartIndex = charCount;
×
NEW
84
  const newPrefixLength = newPrefix.length;
×
NEW
85
  const delta = newPrefixLength - oldPrefixLength;
×
86

87
  const newSelectionStart =
NEW
88
    selectionStart >= lineStartIndex + oldPrefixLength
×
89
      ? selectionStart + delta
90
      : selectionStart;
91

92
  const newSelectionEnd =
NEW
93
    selectionEnd >= lineStartIndex + oldPrefixLength
×
94
      ? selectionEnd + delta
95
      : selectionEnd;
96

NEW
97
  return {
×
98
    value: lines.join('\n'),
99
    selectionStart: newSelectionStart,
100
    selectionEnd: newSelectionEnd,
101
  };
102
}
103

104
export function detectListStyleAtCursor({ value = '', selectionStart = 0 }) {
×
NEW
105
  const lines = value.split('\n');
×
NEW
106
  let charCount = 0;
×
NEW
107
  let targetLineIndex = 0;
×
108

NEW
109
  for (let i = 0; i < lines.length; i++) {
×
NEW
110
    const lineLength = lines[i].length + 1;
×
NEW
111
    if (selectionStart < charCount + lineLength) {
×
NEW
112
      targetLineIndex = i;
×
NEW
113
      break;
×
114
    }
NEW
115
    charCount += lineLength;
×
116
  }
117

NEW
118
  const line = lines[targetLineIndex].trimStart();
×
119

120
  // Detect prefix type
NEW
121
  if (/^\d+\.\s+/.test(line)) return LIST_STYLES.NUMBERED;
×
NEW
122
  if (/^[-*]\s+/.test(line)) return LIST_STYLES.BULLETED;
×
NEW
123
  return null;
×
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc