Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome 浏览器,Up 方向键 光标位置移动异常 #499

Closed
zTree opened this issue Jun 18, 2020 · 4 comments
Closed

Chrome 浏览器,Up 方向键 光标位置移动异常 #499

zTree opened this issue Jun 18, 2020 · 4 comments
Assignees
Milestone

Comments

@zTree
Copy link
Contributor

zTree commented Jun 18, 2020

编辑模式

即时渲染模式

描述问题

首行 设置 标题,第二行开始 都输入 普通文本,输入多行后,用键盘 上下键操作光标,会发现 光标从上倒下,一行一行的移动,是正常的;但从底端往上移动时,异常,会莫名其妙的跳过若干行,而且绝大多数时候,会直接跳到第一行的标题内(目前只发现 Chrome 内有此问题,包括电脑上的,以及 安卓手机上的 Chrome 和 默认浏览器; 但在 Edge 和 Firefox 上无此问题。)

尝试的解决方案:

经过反复测试,怀疑 Chrome 针对 <pre> 内 光标上下行移动时,处理异常。

方案1:把 pre 的 white-space 设置为 normal 光标问题解决,但输入回车后,无法看到换行(此方案废弃)

方案2:对照其他使用 pre 的编辑器(例如:https://stackedit.io/app#),发现使用 <br> 无此问题;所以我在 setValue & input 内 扩展 preview.transform 接口,保证输入时,即时渲染可让外部知晓;然后在 transform 回调内将 ‘\n’ 替换为 <br> ,问题解决。

但此项改动,感觉对内容渲染影响过大,不知会影响到什么,所以不敢擅自提交修改,建议参考 ‘方案2’,针对渲染后的内容在合适的代码位置使用 <br> 替换 '\n'

preview: {
    transform: function(html) {
      html = html.replace(/\n/ig, '<br>');
      return html;
    }
  },

@Vanessa219
Copy link
Owner

没看出什么问题,能录个屏来看看么?
QQ20200618-220237

@zTree
Copy link
Contributor Author

zTree commented Jun 18, 2020

抱歉,没仔细检查,应该是只有 即时渲染模式 有问题

工具压缩的有点儿小,希望不影响你查看
Markdown 教程 - 黑客派 - Google Chrome 2020-06-18 22-23-24 00_00_00--00_00_19

@Vanessa219

@Vanessa219
Copy link
Owner

好像是末尾有 \n 的话,他就会跳过。transform 修改了结构,可能会有其他的问题。不知道再上移时把末尾的 \n 去了行不行。

@zTree
Copy link
Contributor Author

zTree commented Jun 19, 2020

@Vanessa219 果然,把 结尾的 \n 都去掉就行,不用更换 为 <br>, 你看看从核心部位就直接清理是不是就可以了,不知道是否会有其他影响

preview: {
    transform: function(html) {
      html = html.replace(/\n</ig, '<');
      console.log(html);
      return html;
    }
  },

88250 added a commit to 88250/lute that referenced this issue Jun 23, 2020
Chrome 浏览器,Up 方向键 光标位置移动异常
Vanessa219/vditor#499
@Vanessa219 Vanessa219 added this to the 3.3 milestone Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants