mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-10 17:33:24 +01:00
Add focus on edition.
This commit is contained in:
parent
f7c8c13501
commit
f86e3e085b
@ -38,7 +38,7 @@ class EditorComponent extends Events {
|
|||||||
this.registerEvents(this._containerElem);
|
this.registerEvents(this._containerElem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static buildEditor() {
|
private static buildEditor(): JQuery<HTMLElement> {
|
||||||
const result = $('<div></div>').attr('id', 'textContainer').css({
|
const result = $('<div></div>').attr('id', 'textContainer').css({
|
||||||
display: 'none',
|
display: 'none',
|
||||||
zIndex: '8',
|
zIndex: '8',
|
||||||
@ -140,14 +140,14 @@ class EditorComponent extends Events {
|
|||||||
try {
|
try {
|
||||||
actionDispatcher.changeTextToTopic([topicId], text);
|
actionDispatcher.changeTextToTopic([topicId], text);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Hack: For some reasom, editor seems to end up connexted to a deleted node.
|
// Hack: For some reasom, editor seems to end up connected to a deleted node.
|
||||||
// More research required.
|
// More research required.
|
||||||
console.error(`Text could not be update -> ${JSON.stringify(e)}`);
|
console.error(`Text could not be update -> ${JSON.stringify(e)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
show(textOverwrite?: string) {
|
show(textOverwrite?: string): void {
|
||||||
const topic = this._topic;
|
const topic = this._topic;
|
||||||
|
|
||||||
// Hide topic text ...
|
// Hide topic text ...
|
||||||
@ -177,10 +177,11 @@ class EditorComponent extends Events {
|
|||||||
this.setText(text);
|
this.setText(text);
|
||||||
|
|
||||||
// Set the element focus and select the current text ...
|
// Set the element focus and select the current text ...
|
||||||
const inputElem = this.getTextareaElem();
|
const textAreaElem = this.getTextareaElem();
|
||||||
if (inputElem) {
|
if (textAreaElem) {
|
||||||
this.positionCursor(inputElem, textOverwrite === undefined);
|
this.positionCursor(textAreaElem, textOverwrite === undefined);
|
||||||
}
|
}
|
||||||
|
textAreaElem.trigger('focus');
|
||||||
}
|
}
|
||||||
|
|
||||||
private setStyle(fontStyle: {
|
private setStyle(fontStyle: {
|
||||||
@ -192,14 +193,13 @@ class EditorComponent extends Events {
|
|||||||
}) {
|
}) {
|
||||||
const inputField = this.getTextareaElem();
|
const inputField = this.getTextareaElem();
|
||||||
// allowed param reassign to avoid risks of existing code relying in this side-effect
|
// allowed param reassign to avoid risks of existing code relying in this side-effect
|
||||||
/* eslint-disable no-param-reassign */
|
if (!fontStyle.fontFamily) {
|
||||||
if (!$defined(fontStyle.fontFamily)) {
|
|
||||||
fontStyle.fontFamily = 'Arial';
|
fontStyle.fontFamily = 'Arial';
|
||||||
}
|
}
|
||||||
if (!$defined(fontStyle.style)) {
|
if (!fontStyle.style) {
|
||||||
fontStyle.style = 'normal';
|
fontStyle.style = 'normal';
|
||||||
}
|
}
|
||||||
if (!$defined(fontStyle.weight)) {
|
if (!fontStyle.weight) {
|
||||||
fontStyle.weight = 'normal';
|
fontStyle.weight = 'normal';
|
||||||
}
|
}
|
||||||
if (!$defined(fontStyle.size)) {
|
if (!$defined(fontStyle.size)) {
|
||||||
@ -232,14 +232,9 @@ class EditorComponent extends Events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private positionCursor(textareaElem: JQuery<HTMLTextAreaElement>, selectText: boolean) {
|
private positionCursor(textareaElem: JQuery<HTMLTextAreaElement>, selectText: boolean) {
|
||||||
textareaElem.focus();
|
|
||||||
const { length } = this.getTextAreaText();
|
const { length } = this.getTextAreaText();
|
||||||
if (selectText) {
|
const start = selectText ? 0 : length;
|
||||||
// Mark text as selected ...
|
textareaElem[0].setSelectionRange(start, length);
|
||||||
textareaElem[0].setSelectionRange(0, length);
|
|
||||||
} else {
|
|
||||||
textareaElem[0].setSelectionRange(length, length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(update: boolean): void {
|
close(update: boolean): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user