可以用 Javascript 从头开始​​构建文本编辑器吗?

发布于 2024-07-10 15:35:56 字数 279 浏览 3 评论 0原文

我知道 Javascript WYSIWYG 编辑器使用浏览器的内置编辑器模式来运行,但这会带来各种问题。

能否用 JS 从头开始​​构建一个编辑器,就像 Buzzword 人们用 flash/flex 所做的那样? 我最近看到这篇博文我只是想知道是否可以使用 Javascript 构建(至少在一定程度上)?

I am aware that Javascript WYSIWYG editors use the inbuilt editor mode of the browser to function, but that comes up with various problems and issues.

Can an editor be built from scratch in JS, something like what Buzzword people have done with flash/flex? I came across this blog post recently and I am just wondering if this can be built (atleast to a moderate extent) using Javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

秋千易 2024-07-17 15:35:56

这取决于你所说的“从头开始”是什么意思。 Google Docs 提供了一个非常好的 JS 文本编辑器。 你是这个意思吗 ?

It depends what you mean by "from scratch". Google Docs provides a pretty good text editor in JS. Is that what you mean ?

半暖夏伤 2024-07-17 15:35:56

当然你可以做到,而且不是很难。
但在重新发明轮子之前,请先看看所有现有的。
其中许多确实写得非常好并且是开源的。

Of course you can do it and it is not very difficult.
But before reinventing the wheel please take a look at all the existing ones.
Many of them are really very well written and open source.

開玄 2024-07-17 15:35:56

几乎任何事情都可以用 JavaScript 完成。 您拥有基本的构建工具 - 您可以拦截所有鼠标事件和几乎所有键盘事件。 您可以使用 GIF 动画来模拟插入符号。 更棘手的部分可能是测量文本的大小,以便您可以将插入符号放置在您需要的位置。 我不太确定你怎么能做到这一点。 但如果你弄清楚了这一点,剩下的都是可行的。 尽管它确实需要大量重新发明轮子的代码。

Almost anything can be done with JavaScript. You have the basic building tools right there - you can intercept all mouse events and nearly all keyboard events. You can use a GIF animation for simulating the caret. The trickier part might be measuring the size of text so that you can position your caret where you need to. I'm not exactly sure how you could do that. But if you figure that out, the rest is doable. Although it will really require tons of wheel-reinventing code.

孤芳又自赏 2024-07-17 15:35:56

让我想起我之前做过的一个小实验...我基本上尝试通过简单地监听 DIV 上的按键并将它们作为新节点插入到 DIV 中来创建一个原始编辑器。 想象一下,每个角色都会被包裹在一个标签中! 它确实有效。 但是,一旦达到几个段落,节点插入和删除就会变得相当慢。 你会输入一个字符,它只会在稍微延迟后才出现,这简直令人无法接受,最终我放弃了。 无论如何,这只是我想尝试的一个随机的事情。

回到你的问题,我想知道这是否可以单独在 JS 中复制,因为坦率地说,与 JS 相比,闪存具有卓越的原始处理能力。 即使它在技术上是可行的,我也怀疑它是否足够快以实际工作良好。 我的两分钱!

Reminds me of a little experiment I did sometime back... I basically tried to create a primitive editor by simply listening to keypresses on a DIV and to insert them into the DIV as a new node. So imagine, each character would be wrapped in a tag! It actually worked. But, once it reaches a couple of paragraphs, node insertion and deletion becomes rather slow. You will type a character, and it would only appear after a slight delay, and this simply unacceptable, and eventually I just gave up. Anyway it was just a random thing I wanted to try out..

Coming back to your question, I wonder if this can be replicated in JS alone as frankly the flash has superior raw processing power compared to JS. Even if it's technically feasible, I doubt whether it will be fast enough to actually work well. My two cents!

筑梦 2024-07-17 15:35:56

阿特伍德定律

任何可以用 JavaScript 编写的应用程序最终都会
用 JavaScript 编写。

Atwood's Law:

Any application that can be written in JavaScript, will eventually be
written in JavaScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文