@sequent-org/moodboard 1.2.43 → 1.2.44
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.
package/package.json
CHANGED
|
@@ -473,6 +473,10 @@ export class SelectTool extends BaseTool {
|
|
|
473
473
|
type: 'text',
|
|
474
474
|
position: posData.position,
|
|
475
475
|
properties: { content: textContent },
|
|
476
|
+
caretClick: {
|
|
477
|
+
clientX: event?.originalEvent?.clientX,
|
|
478
|
+
clientY: event?.originalEvent?.clientY
|
|
479
|
+
},
|
|
476
480
|
create: false
|
|
477
481
|
});
|
|
478
482
|
return;
|
|
@@ -2180,6 +2184,59 @@ export class SelectTool extends BaseTool {
|
|
|
2180
2184
|
document.head.appendChild(styleEl);
|
|
2181
2185
|
this.textEditor = { active: true, objectId, textarea, wrapper, world: this.textEditor.world, position, properties: { fontSize }, objectType, _phStyle: styleEl };
|
|
2182
2186
|
|
|
2187
|
+
// Если переходим в редактирование существующего текста по двойному клику,
|
|
2188
|
+
// устанавливаем каретку по координате клика между буквами
|
|
2189
|
+
try {
|
|
2190
|
+
const click = (object && object.caretClick) ? object.caretClick : null;
|
|
2191
|
+
if (!create && objectId && click && typeof window !== 'undefined') {
|
|
2192
|
+
setTimeout(() => {
|
|
2193
|
+
try {
|
|
2194
|
+
const el = window.moodboardHtmlTextLayer ? window.moodboardHtmlTextLayer.idToEl.get(objectId) : null;
|
|
2195
|
+
const fullText = (typeof textarea.value === 'string') ? textarea.value : '';
|
|
2196
|
+
if (!el || !fullText || !el.firstChild) return;
|
|
2197
|
+
const textNode = el.firstChild;
|
|
2198
|
+
const len = textNode.textContent.length;
|
|
2199
|
+
if (len === 0) {
|
|
2200
|
+
textarea.selectionStart = textarea.selectionEnd = 0;
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
const doc = el.ownerDocument || document;
|
|
2204
|
+
let bestIdx = 0;
|
|
2205
|
+
let bestDist = Infinity;
|
|
2206
|
+
for (let i = 0; i <= len; i++) {
|
|
2207
|
+
const range = doc.createRange();
|
|
2208
|
+
range.setStart(textNode, i);
|
|
2209
|
+
range.setEnd(textNode, i);
|
|
2210
|
+
const rects = range.getClientRects();
|
|
2211
|
+
const rect = rects && rects.length > 0 ? rects[0] : range.getBoundingClientRect();
|
|
2212
|
+
if (rect && isFinite(rect.left) && isFinite(rect.top)) {
|
|
2213
|
+
if (click.clientX >= rect.left && click.clientX <= rect.right &&
|
|
2214
|
+
click.clientY >= rect.top && click.clientY <= rect.bottom) {
|
|
2215
|
+
bestIdx = i;
|
|
2216
|
+
bestDist = 0;
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
const cx = Math.max(rect.left, Math.min(click.clientX, rect.right));
|
|
2220
|
+
const cy = Math.max(rect.top, Math.min(click.clientY, rect.bottom));
|
|
2221
|
+
const dx = click.clientX - cx;
|
|
2222
|
+
const dy = click.clientY - cy;
|
|
2223
|
+
const d2 = dx * dx + dy * dy;
|
|
2224
|
+
if (d2 < bestDist) {
|
|
2225
|
+
bestDist = d2;
|
|
2226
|
+
bestIdx = i;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
|
|
2231
|
+
const caret = clamp(bestIdx, 0, fullText.length);
|
|
2232
|
+
textarea.selectionStart = textarea.selectionEnd = caret;
|
|
2233
|
+
if (typeof textarea.scrollTop === 'number') textarea.scrollTop = 0;
|
|
2234
|
+
console.log('🧭 Text caret set', { objectId, caret, len: fullText.length });
|
|
2235
|
+
} catch (_) {}
|
|
2236
|
+
}, 0);
|
|
2237
|
+
}
|
|
2238
|
+
} catch (_) {}
|
|
2239
|
+
|
|
2183
2240
|
// Если редактируем записку — скрываем PIXI-текст записки (чтобы не было дублирования)
|
|
2184
2241
|
if (objectType === 'note' && objectId) {
|
|
2185
2242
|
try {
|