Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL indentation not working #179

Open
istvanberes opened this issue Mar 20, 2018 · 2 comments
Open

RTL indentation not working #179

istvanberes opened this issue Mar 20, 2018 · 2 comments

Comments

@istvanberes
Copy link

istvanberes commented Mar 20, 2018

If you set the direction to rtl on the ng-wig component the indentation not working.

https://plnkr.co/edit/44oDh3A9MN05rpWXgSDR?p=preview

The indent button add a new element, but the margin are in the left: <blockquote style="margin: 0 0 0 40px;

@stevermeister
Copy link
Owner

wow, true, thank you for reporting it!
any idea how to fix it?

@istvanberes
Copy link
Author

I added some custom buttons with custom functions (I call these function also if you pres the Tab/Shift Tab)

` function indentInNgWig() {
const selection = window.getSelection();
const ngWig = findAncestor(selection.focusNode, '.ng-wig');
const rtl = isRTL(ngWig);
if (!hasLiParent(selection, ngWig) && rtl) {
document.execCommand('formatBlock', false, 'p');
changeMargin(ngWig, true);
} else {
document.execCommand('indent', false);
}
}

function outdentInNgWig() {
const selection = window.getSelection();
const ngWig = findAncestor(selection.focusNode, '.ng-wig');
const rtl = isRTL(ngWig);
if (!hasLiParent(selection, ngWig) && rtl) {
changeMargin(ngWig, false);
} else {
document.execCommand('outdent', false);
}
}

function changeMargin(ngWigEditor, indent: boolean) {
const selectedElement = window.getSelection().focusNode.parentNode as HTMLElement;
const declaration = selectedElement.style;
let margin = declaration.marginRight;
const currentValue = (margin !== '') ? parseInt(margin.replace('px', ''), 10) : 0;
if (indent) {
margin = currentValue + indentation + 'px';
declaration.marginRight = margin;
}
if (!indent && currentValue >= indentation) {
if (currentValue === indentation) {
while (selectedElement.childNodes.length > 0) {
selectedElement.parentNode.insertBefore(selectedElement.childNodes[0], selectedElement);
}
selectedElement.remove();
} else if (currentValue > indentation) {
margin = (currentValue - indentation) + 'px';
declaration.marginRight = margin;
}
}
}

function isRTL(ngWigEditor) {
const computedStyle = getComputedStyle(ngWigEditor) as any;
if (computedStyle.direction === 'rtl') {
return true;
}
return false;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants