@kaitify/core 0.0.1-beta.24 → 0.0.1-beta.26
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/lib/kaitify-core.es.js +51 -4
- package/lib/kaitify-core.umd.js +1 -1
- package/lib/model/Editor.d.ts +4 -0
- package/package.json +1 -1
package/lib/kaitify-core.es.js
CHANGED
|
@@ -38050,10 +38050,12 @@ class Editor {
|
|
|
38050
38050
|
this.delete();
|
|
38051
38051
|
return;
|
|
38052
38052
|
} else if (node.isText()) {
|
|
38053
|
-
const
|
|
38054
|
-
|
|
38055
|
-
|
|
38056
|
-
|
|
38053
|
+
const charArray = Array.from(node.textContent.substring(0, offset));
|
|
38054
|
+
const deleteChart = charArray.pop();
|
|
38055
|
+
const deleteChartLength = deleteChart.length;
|
|
38056
|
+
node.textContent = charArray.join("") + node.textContent.substring(offset);
|
|
38057
|
+
this.selection.start.offset = offset - deleteChartLength;
|
|
38058
|
+
this.selection.end.offset = offset - deleteChartLength;
|
|
38057
38059
|
if (isZeroWidthText(deleteChart)) {
|
|
38058
38060
|
this.delete();
|
|
38059
38061
|
return;
|
|
@@ -38318,6 +38320,51 @@ class Editor {
|
|
|
38318
38320
|
}
|
|
38319
38321
|
return `<style>${styles2}</style><div class="kaitify">${this.$el.innerHTML}</div>`;
|
|
38320
38322
|
}
|
|
38323
|
+
/**
|
|
38324
|
+
* 判断光标是否完全在可视范围内
|
|
38325
|
+
*/
|
|
38326
|
+
isSelectionInView() {
|
|
38327
|
+
if (this.selection.focused()) {
|
|
38328
|
+
const focusDom = this.findDom(this.selection.end.node);
|
|
38329
|
+
const isInView = (scrollElement) => {
|
|
38330
|
+
const scrollHeight = element.getScrollHeight(scrollElement);
|
|
38331
|
+
const scrollWidth = element.getScrollWidth(scrollElement);
|
|
38332
|
+
if (scrollElement.clientHeight < scrollHeight || scrollElement.clientWidth < scrollWidth) {
|
|
38333
|
+
const selection = window.getSelection();
|
|
38334
|
+
const range = selection.getRangeAt(0);
|
|
38335
|
+
const rects = range.getClientRects();
|
|
38336
|
+
let target = range;
|
|
38337
|
+
if (rects.length == 0) {
|
|
38338
|
+
target = focusDom;
|
|
38339
|
+
}
|
|
38340
|
+
const childRect = target.getBoundingClientRect();
|
|
38341
|
+
const parentRect = scrollElement.getBoundingClientRect();
|
|
38342
|
+
if (scrollElement.clientHeight < scrollHeight) {
|
|
38343
|
+
if (childRect.top < parentRect.top || childRect.bottom > parentRect.bottom) {
|
|
38344
|
+
return false;
|
|
38345
|
+
}
|
|
38346
|
+
}
|
|
38347
|
+
if (scrollElement.clientWidth < scrollWidth) {
|
|
38348
|
+
if (childRect.left < parentRect.left || childRect.right > parentRect.right) {
|
|
38349
|
+
return false;
|
|
38350
|
+
}
|
|
38351
|
+
}
|
|
38352
|
+
}
|
|
38353
|
+
return true;
|
|
38354
|
+
};
|
|
38355
|
+
let inView = true;
|
|
38356
|
+
let dom = focusDom;
|
|
38357
|
+
while (element.isElement(dom) && dom != document.documentElement) {
|
|
38358
|
+
if (!isInView(dom)) {
|
|
38359
|
+
inView = false;
|
|
38360
|
+
break;
|
|
38361
|
+
}
|
|
38362
|
+
dom = dom.parentNode;
|
|
38363
|
+
}
|
|
38364
|
+
return inView;
|
|
38365
|
+
}
|
|
38366
|
+
return true;
|
|
38367
|
+
}
|
|
38321
38368
|
/**
|
|
38322
38369
|
* 配置编辑器,返回创建的编辑器
|
|
38323
38370
|
*/
|