Index Third
Index Third
this.textLines[rowIndex] = firstPortion;
this.textLines.splice(rowIndex + 1, 0, secondPortion);
} else if (columnIndex == columnCount) {
this.textLines.splice(rowIndex + 1, 0, Array.from(""));
}
}
}
console.log(this.textLines[rowIndex].join(""));
} else if (columnIndex == columnCount) {
this.textLines[rowIndex].push(character);
}
}
}
this.caret.setIndexes(rowIndex, columnIndex);
this.caret.startBlinking();
}
let i = this.caret.getRowIndex();
let j = this.caret.getColumnIndex();
this.caret.setIndexes(i, j + 1);
this.caret.startBlinking();
} else if (event.key === "Enter") {
this.splitLine(i, j);
this.caret.setIndexes(i + 1, 0);
this.caret.startBlinking();
} else if (event.key === "Backspace") {
if (j == 0) {
if (i != 0) {
const nextColumnCount = this.textLines[i - 1].length
this.caret.setIndexes(i - 1, nextColumnCount);
this.removeLine(i);
}
} else {
this.removeCharacter(i, j - 1);
this.caret.setIndexes(i, j - 1);
}
this.caret.startBlinking();
} else if (event.key === "Home") {
this.caret.setColumnIndex(0);
this.caret.startBlinking();
} else if (event.key === "End") {
this.caret.setColumnIndex(columnCount);
this.caret.startBlinking();
} else if (event.key === "ArrowUp") {
const nextColumnCount = this.textLines[i - 1].length
this.caret.setIndexes(Math.max(0, Math.min(i - 1, rowCount)),
Math.min(j, nextColumnCount));
this.caret.startBlinking();
} else if (event.key === "ArrowDown") {
if (i < rowCount - 1) {
console.log("i = %d, j = %d, rowCount = %d", i, j, rowCount);
const nextColumnCount = this.textLines[i + 1].length
this.caret.setIndexes(i + 1, Math.min(j, nextColumnCount));
}
this.caret.startBlinking();
} else if (event.key === "ArrowLeft") {
this.caret.setIndexes(i, Math.max(0, Math.min(j - 1, columnCount)));
this.caret.startBlinking();
} else if (event.key === "ArrowRight") {
this.caret.setIndexes(i, Math.max(0, Math.min(j + 1, columnCount)));
this.caret.startBlinking();
} else if (event.key === "Tab") {
this.setCharacter(i, j, " ");
this.setCharacter(i, j, " ");
this.setCharacter(i, j, " ");
this.setCharacter(i, j, " ");
this.caret.setIndexes(i, j + 4);
this.caret.startBlinking();
if (captureEvent) {
console.log("capturing event");
event.stopPropagation();
}
}
this.ref = React.createRef();
this.caretRef = React.createRef();
}
componentDidMount(): void {
window.addEventListener("click", (event) => {
this.props.textEditor.caret.stopBlinking();
console.log("Click received on ", event.currentTarget, " originated at
", event.target);
});
event.stopPropagation();
});
}
public render() {
const textLineComponents: JSX.Element[] = [];
for (let i = 0; i < this.props.textEditor.getTextLines().length; ++i) {
textLineComponents.push(<TextLineComponent key={i}
rowIndex={i}
text={this.props.textEditor.getTextLines()
[i].join("")}
textEditor={this.props.textEditor} />)
}
return (
<div className='textEditor' id='textEditor' ref={this.ref}>
{textLineComponents}
<CaretComponent ref={this.caretRef} />
</div>
)
}
}
root.render(
<TextEditorComponent textEditor={component} />
);
// component.addLine("bye bye");