简体   繁体   English

更改光标位置时防止textarea自动滚动

[英]Prevent textarea from automatically scrolling when I change cursor position

I have a textarea with a lot of text and a vertical scrollbar. 我有一个包含大量文本和垂直滚动条的textarea。 When I move the cursor beyond the visible area (imagine having a long document, and then pressing down arrow many times until cursor goes off screen), the browser will automatically scroll the cursor into view, so it always remains visible. 当我将光标移到可见区域之外(想象有一个长文档,然后多次按下箭头直到光标离开屏幕)时,浏览器将自动将光标滚动到视图中,因此它始终保持可见状态。

How do I prevent this behavior? 如何防止这种行为? I need to be able to move cursor beyond the visible area, without it being autoscrolled. 我需要能够将光标移动到可见区域之外,而不会自动滚动。

(technically, it's not a textarea but a React-based text editor, in dom it's a div with content-editable set to true, not sure if it matters) (从技术上讲,它不是一个文本区域,而是一个基于React的文本编辑器,实际上它是一个div,其content-editable设置为true,不确定是否重要)

It doesn't appear this is possible. 看来这是不可能的。 From the spec: 从规格:

It MUST be possible to put the caret in any of the Legal Caret Positions programatically and for the caret to be visible in these in any editing host that is in the "events", "caret" or "typing" state. 必须有可能以编程方式将插入标记置于任何法律插入标记位置,并且在处于“事件”,“插入标记”或“键入”状态的任何编辑主机中,都可以在这些标记中看到插入标记。

https://w3c.github.io/editing/contentEditable.html#caret_positions https://w3c.github.io/editing/contentEditable.html#caret_positions

"MUST put the caret" & "MUST be visible" indicate this. “必须插入插入符号”和“必须可见”表示这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM