首页 > 解决方案 > 如何在编辑器中实现长行的软换行?

问题描述

我需要在我的临时文本编辑器中实现长行的软(视觉)中断。我在决定时遇到问题:

基本上我正在寻找可能接近设计模式和/或某人经验丰富的建议的东西。

当前的缓冲区结构如下:

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);

标签: design-patternsword-wraptext-editorglib

解决方案


推荐阅读