有右引力标记的例子吗?
Quoted from here:
The standard left-to-right cursor is a
mark with right gravity (when you
type, the cursor stays on the right
side of the text you're typing).
Now I see what's an mark with right gravity.
But I still don't have an idea what's a mark with left gravity like,is there an example of left gravity mark?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标记用作文本缓冲区的稳定指针。光标就是一个例子,但标记也经常用于内部(用户不可见)原因。假设有一个标记指向以下单词的中间(
|
表示标记,而不是文本中的字符):如果我们在“foo”之后和“bar”之前插入文本“baz”标记的行为会根据重力而有所不同。
对于左重力标记:
使用右重力(如光标):
左重力的一个很好的用例是指向某行文本开头的标记。使用右重力时,文本插入可能会将其移动到其他位置,而使用左重力时,文本插入将始终指向行开头(当然,前提是之前的换行符未被删除)。
Marks are used as stable pointers into a text buffer. Cursor is one example, but marks are often used for internal (not visible to user) reasons too. Suppose there's a mark pointing in to the middle of the following word (
|
signifies the mark, not a character in the text):If we insert text "baz" after "foo" and before "bar" the mark will behave differently depending on the gravity.
For mark with left gravity:
With right gravity (like the cursor):
A good usecase for left gravity is a mark that points to the beginning of some line of text. With right gravity, text insertion could shift it to somewhere else, with left gravity it will always point to the line beginning (provided that linefeed before is not deleted, of course).