design-patterns - 如何在编辑器中实现长行的软换行?
问题描述
我需要在我的临时文本编辑器中实现长行的软(视觉)中断。我在决定时遇到问题:
- 应该如何(如果应该)存储关于每条长线的(仅可视)断点的信息?
- 应该如何(如果……)存储关于逻辑长行中光标位置的信息?
- 滚动时,从哪里获取屏幕上第一行的信息,例如。长线的第二部分已经部分滚动到视口之外?
基本上我正在寻找可能接近设计模式和/或某人经验丰富的建议的东西。
当前的缓冲区结构如下:
typedef struct
{
off_t curs1; /* pos. of the cursor from beginning of file. */
off_t curs2; /* pos. from end of file */
GPtrArray *b1; /* all data up to curs1 */
GPtrArray *b2; /* all data from end of file down to curs2 */
} edit_buf_t;
指针数组包含大量65535
字节,因此,例如,为了在 之前获得一个字节curs1
,可以:
/* Size of the buffer in bits and max value */
#define EDIT_BF_SZ_BITS 16
#define EDIT_BF_SZ (((off_t) 1) << EDIT_BF_SZ_BITS)
/* Buffer size mask of all bits set */
#define EDIT_BF_SZ_MASK (EDIT_BF_SZ - 1)
b = g_ptr_array_index (buf->b1, byte_index >> EDIT_BF_SZ_BITS);
return (char *) b + (byte_index & EDIT_BF_SZ_MASK);
解决方案
推荐阅读
- javascript - 如何将 PHP 变量传递给 AJAX URL
- discord - 禁止命令:ReferenceError:消息未定义(Discord.Js)
- java - 线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:索引 2 超出范围
- php - 如何将 mikrotik 命令结果发送到 php
- asp.net - 为请求记录创建唯一字符串 ASP.NET Core MVC
- firebase - 如何限制firebase函数的实例数
- rdf - RDF OWL - 一个语句可以用作另一个语句的对象吗?
- python-3.x - 中断 input() 语句
- android - 获取有关协程的混合消息
- python - 如何将web url中的windows url替换为web url并且需要在python中下载pdf文件