⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.c

📁 dtelent是开源的开发项目
💻 C
字号:
/* editor.c */

#include <windows.h>

#include "editor.h"

#include "emul.h"
#include "term.h"
#include "lines.h"
#include "resource.h"

#define CM_FREE ID_CM_FREE /* free cursor movement */
#define CM_TEXT ID_CM_TEXT /* restricted cursor movement */

static int nCursorMovement = CM_TEXT;

int editGetCMMode (void)
{
    return nCursorMovement;
}

int editSetCMMode (int nCM)
{
    int nOldCM;

    nOldCM = nCursorMovement;
    nCursorMovement = nCM;
    return nOldCM;
}

/* Move the cursor
 *
 * in the comments 'epl' is end of physical line (term.winSize.cx-1)
 *                 'eol' is end of logical line (line->len -1)
 */
void editMoveCursor(int direction)
{
    int lineIdx;
    Line *line;

    switch (direction) {
    case EFK_LOCAL_LEFT:
	if (term.cursor.x > 0)
	    term.cursor.x--;
	else {
	    lineIdx = linesTerminalToLine(term.cursor.y);
	    if (lineIdx==0) return;
	    --lineIdx;
	    linesCreateTo(lineIdx);
	    line = linesGetLine(lineIdx);

	    if (line->len > term.winSize.cx ||
		line->len == term.winSize.cx && ! line->wrapped) {
		term.cursor.x = term.winSize.cx;        /* eopl+1*/

	    } else if (nCursorMovement == CM_FREE){
		term.cursor.x = term.winSize.cx - 1;    /* eopl */

	    } else if (line->wrapped && line->len>0) {
		term.cursor.x = line->len -1;           /* eoll */

	    } else {
		term.cursor.x = line->len;              /* eoll+1 */
	    }
	    --term.cursor.y;
	}
	break;

    case EFK_LOCAL_RIGHT:
	lineIdx = linesTerminalToLine(term.cursor.y);
	linesCreateTo(lineIdx);
	line = linesGetLine(lineIdx);

	if (((term.cursor.x < term.winSize.cx -1) &&
	    (nCursorMovement == CM_FREE ||
	     term.cursor.x < line->len -1 ||
	     (term.cursor.x == line->len -1 && ! line->wrapped))) ||
	    (term.cursor.x == term.winSize.cx -1 &&
	     line->len >= term.winSize.cx && ! line->wrapped)) {
	    ++term.cursor.x;
	} else {
	    term.cursor.x = 0;
	    ++term.cursor.y;
	}
	break;

    case EFK_LOCAL_HOME:
	lineIdx = linesTerminalToLine(term.cursor.y);
	linesCreateTo(lineIdx);

	while (lineIdx > 0 &&
	       (line = linesGetLine (lineIdx-1))->wrapped) {
	    --term.cursor.y;
	    --lineIdx;
	}
	term.cursor.x = 0;
	break;

    case EFK_LOCAL_END:
	lineIdx = linesTerminalToLine(term.cursor.y);
	linesCreateTo(lineIdx);
	line = linesGetLine(lineIdx);
	while (line->wrapped) {
	    ++term.cursor.y;
	    ++lineIdx;
	    line = linesGetLine(lineIdx);
	}
	term.cursor.x = line->len;
	break;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -