lutra 0.1.12 → 0.1.14

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.
@@ -171,7 +171,8 @@
171
171
  border-radius: var(--menu-border-radius);
172
172
  box-shadow: 0 0.5rem 1rem var(--shadow-color);
173
173
  background-color: var(--menu-background-color);
174
- width: var(--width, 25ch);
174
+ width: var(--width, fit-content);
175
+ max-width: var(--max-width, 50ch);
175
176
  overflow-x: clip;
176
177
  overflow-y: auto;
177
178
  scrollbar-width: thin;
@@ -109,6 +109,7 @@
109
109
  --inset-block: 0.5rem;
110
110
  --inset-inline: 1rem;
111
111
  border-radius: none;
112
+ white-space: nowrap;
112
113
  }
113
114
 
114
115
  li.rounded .Item,
@@ -128,10 +129,17 @@
128
129
  outline: none;
129
130
  }
130
131
 
132
+ li .Item span.Content {
133
+ display: inline-flex;
134
+ align-items: center;
135
+ white-space: nowrap;
136
+ }
137
+
131
138
  li .Item span.Shortcut {
132
139
  font-size: max(0.75em, 9px);
133
140
  text-align: right;
134
141
  color: var(--menu-text-color-subtle);
142
+ white-space: nowrap;
135
143
  }
136
144
 
137
145
  li .Item:not(.Custom):active {
@@ -104,7 +104,10 @@ export function matchOnType(el, e) {
104
104
  items.forEach((el) => {
105
105
  const contentEl = el.querySelector("span.Content") ?? el.querySelector("label");
106
106
  if (contentEl) {
107
- contentEl.innerHTML = contentEl.textContent;
107
+ // Remove underlines while preserving other elements (like icons)
108
+ contentEl.querySelectorAll("u").forEach((u) => {
109
+ u.replaceWith(u.textContent);
110
+ });
108
111
  }
109
112
  });
110
113
  }
@@ -132,13 +135,48 @@ export function matchOnType(el, e) {
132
135
  // add underline to the matched text
133
136
  matches.forEach((el) => {
134
137
  const contentEl = el.querySelector("span.Content, label");
135
- const text = contentEl?.textContent?.trim();
136
- if (text) {
137
- const index = text.toLowerCase().indexOf(keyMemory);
138
- const first = text.slice(0, index);
139
- const last = text.slice(index + keyMemory.length);
140
- const middle = text.slice(index, index + keyMemory.length);
141
- contentEl.innerHTML = `${first}<u>${middle}</u>${last}`;
138
+ if (!contentEl)
139
+ return;
140
+ // Find all text nodes within contentEl
141
+ const walker = document.createTreeWalker(contentEl, NodeFilter.SHOW_TEXT, null);
142
+ let textNode;
143
+ let fullText = "";
144
+ const textNodes = [];
145
+ while (textNode = walker.nextNode()) {
146
+ textNodes.push(textNode);
147
+ fullText += textNode.textContent;
148
+ }
149
+ const lowerText = fullText.toLowerCase();
150
+ const matchIndex = lowerText.indexOf(keyMemory);
151
+ if (matchIndex === -1)
152
+ return;
153
+ // Calculate position across text nodes
154
+ let currentPos = 0;
155
+ for (const node of textNodes) {
156
+ const nodeText = node.textContent || "";
157
+ const nodeLength = nodeText.length;
158
+ const nodeStart = currentPos;
159
+ const nodeEnd = currentPos + nodeLength;
160
+ // Check if this node contains any part of the match
161
+ if (matchIndex < nodeEnd && matchIndex + keyMemory.length > nodeStart) {
162
+ const relativeStart = Math.max(0, matchIndex - nodeStart);
163
+ const relativeEnd = Math.min(nodeLength, matchIndex + keyMemory.length - nodeStart);
164
+ const before = nodeText.slice(0, relativeStart);
165
+ const match = nodeText.slice(relativeStart, relativeEnd);
166
+ const after = nodeText.slice(relativeEnd);
167
+ const fragment = document.createDocumentFragment();
168
+ if (before)
169
+ fragment.appendChild(document.createTextNode(before));
170
+ if (match) {
171
+ const u = document.createElement("u");
172
+ u.textContent = match;
173
+ fragment.appendChild(u);
174
+ }
175
+ if (after)
176
+ fragment.appendChild(document.createTextNode(after));
177
+ node.replaceWith(fragment);
178
+ }
179
+ currentPos = nodeEnd;
142
180
  }
143
181
  });
144
182
  if (keyMemory.length === 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lutra",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",