Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
el cursor se movió a la posición de inicio al insertar caracteres en div contenteditable

Estaba copiando facebook draftjs, en el que solo se agregaron características principales que aceptan la inserción nativa de caracteres, el caso aquí es que el cursor se movió a la posición inicial de una línea donde se escribió al insertar caracteres en div contenteditable y luego actualizar el estado.

Desde la salida de la consola, el evento 'onSelect' maneja y emite el estado de selección correcto del objeto dom que activa el doble, el primero para enfocar la posición del área de texto, el segundo ocurre después de que el evento 'onInput' regresa a medida que cambia la posición del cursor .

El problema aquí es que después de insertar caracteres (que funciona), no funcionó como se esperaba para mantener el cursor en la posición donde estaba, pero el valor inicial, vea el registro de la consola captura de pantalla.png . Y no tengo idea de dónde está el truco y el truco para hacer esto, como en la parte relevante de draftjs.

 function onSelect(_this: Editor): void { console.log('SELECT') const { editorState } = _this.props if(_this._blockSelectEvent || _this._latestEditorState != _this.props.editorState) { return } // forceSelection const selection = getCastSelection(editorState, getContentEditable(_this)) let newEditorState: EditorState if(selection !== editorState.getSelection()) { newEditorState = editorState.acceptSelection(selection) _this.sync(newEditorState) } }
 function onBeforeInput( _this: Editor, e: SyntheticInputEvent<HTMLElement> ): void { console.log('BEFOREINPUT') const editorState = _this._latestEditorState, { data } = e if(!data) { return } const selection = editorState.getSelection(), inlineStyle = editorState.getInlineStyle(), chars = data if(!selection.collapsed()) {} let newEditorState = replaceChars( editorState, chars, inlineStyle, false ) _this._pendingEditorState = newEditorState }
 function onInput( _this: Editor, e: ?SyntheticInputEvent<> ): void { console.log('INPUT') if(_this._pendingEditorState != undefined) { _this.sync(_this._pendingEditorState) _this._pendingEditorState = undefined } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!