mesdan
Version:
Latinî mesdan ile Osmanî metin yazmak için hazırlanmış bir alettir.
57 lines (56 loc) • 2.27 kB
JavaScript
import { $getSelection, $isRangeSelection, $isTextNode } from 'lexical';
import { silinecekOsmaniHarfAdediBaşra, silinecekOsmaniHarfAdediSonra } from './silinecek-osmani-harf-adedi';
export function silOsmaniHarfiBaşra(metinger, vaqa) {
metinger.update(() => {
let selection = $getSelection();
if (!$isRangeSelection(selection) || !selection.isCollapsed())
return;
const anchor = selection.anchor;
const offset = anchor.offset;
let node = anchor.getNode();
let marMetin = node.getTextContent().slice(0, offset);
if (offset === 0) {
const prevNode = node.getPreviousSibling();
if ($isTextNode(prevNode)) {
marMetin = prevNode.getTextContent() + marMetin;
}
}
const silinecekAdet = silinecekOsmaniHarfAdediBaşra(marMetin);
if (silinecekAdet > 0) {
vaqa.preventDefault();
vaqa.stopPropagation();
// for (let i = 0; i < silinecekAdet; i++) {
// selection.modify('extend', true, 'character');
// }
selection.modify('extend', true, 'character');
selection.removeText();
}
});
}
export function silOsmaniHarfiSonra(metinger, vaqa) {
metinger.update(() => {
const selection = $getSelection();
if (!$isRangeSelection(selection) || !selection.isCollapsed())
return;
const anchor = selection.anchor;
const offset = anchor.offset;
let node = anchor.getNode();
let atiMetin = node.getTextContent().slice(offset);
if (offset === node.getTextContentSize()) {
const nextNode = node.getNextSibling();
if ($isTextNode(nextNode)) {
atiMetin = atiMetin + nextNode.getTextContent();
}
}
const silinecekAdet = silinecekOsmaniHarfAdediSonra(atiMetin);
if (silinecekAdet > 0) {
vaqa.preventDefault();
vaqa.stopPropagation();
// for (let i = 0; i < silinecekAdet; i++) {
// selection.deleteCharacter(false); // sonra
// }
selection.modify('extend', false, 'character');
selection.removeText();
}
});
}