📄 edit.c
字号:
cbFilename = 0;
}
clearbuf();
fScreen = TRUE;
break;
case 0x45: /* ALT-E -- End of Text */
case 0x65: /* ALT-e */
pEdit->oBufInsert = pEdit->oBufLast;
coordCursor_oBuf ();
fScreen = TRUE;
break;
case 0x01: /* ALT-UP Arrow - Cursor to top of screen */
pEdit->iLine = pEdit->iRowMin;
pEdit->iCol = pEdit->iColMin;
break;
case 0x02: /* ALT Down Arrow - Cursor to bottom of screen */
pEdit->iLine = pEdit->iRowMin;
i = pEdit->iLine;
while ((pEdit->Line[i+1] < EMPTY) &&
(i < pEdit->iRowMax)) {
pEdit->iLine++;
i = pEdit->iLine;
}
pEdit->iCol = pEdit->iColMax;
coordCursor_oBuf ();
break;
case 0x03: /* ALT-Left Arrow - Cursor to BOL */
pEdit->iCol = pEdit->iColMin;
break;
case 0x04: /* ALT-Right Arrow - Cursor to EOL */
i = pEdit->iLine;
if (pEdit->Line[i+1] < EMPTY) {
pEdit->iCol =
pEdit->iColMin +
pEdit->Line[i+1] -
pEdit->Line[i];
i = pEdit->iLine+1;
if ((pBuff[pEdit->Line[i]-1] == 0x0A)
&& (pEdit->iCol > pEdit->iColMin))
pEdit->iCol--;
}
else pEdit->iCol = pEdit->iColMin +
pEdit->oBufLast - pEdit->Line[i];
break;
case 0x56: /* ALT-V Make nontext chars Visible/Invisible */
case 0x76: /* ALT-v */
if (pEdit->fVisible) {
for (i=0; i <= pEdit->oBufLast; i++)
if (pBuff[i] == 0x07)
pBuff[i] = 0x20;
pEdit->fVisible = FALSE;
pEdit->bSpace = 0x20;
} else {
for (i=0; i<=pEdit->oBufLast; i++)
if (pBuff[i] == 0x20)
pBuff[i] = 0x07;
pEdit->fVisible = TRUE;
pEdit->bSpace = 0x07;
}
fScreen = TRUE;
break;
case 0x4F: /* ALT-O OpenFile */
case 0x6F: /* ALT-o */
if (!fh) {
clearbuf();
OpenAFile();
fScreen = TRUE;
}
break;
case 0x53: /* ALT S - SaveFile */
case 0x73: /* ALT s */
if ((fh) && (fModified)) {
if (pEdit->fVisible) { /* fix visible characters */
for (i=0; i <=pEdit->iBufMax; i++)
if (pBuff[i] == 0x07)
pBuff[i] = 0x20;
pEdit->fVisible = FALSE;
}
if (fModified) {
erc = CheckErc(6, SetFileLFA(fh, 0));
if (!erc)
erc = CheckErc(5, SetFileSize(fh,
pEdit->oBufLast));
if (!erc)
erc = CheckErc(3, WriteBytes (fh, pBuf1,
pEdit->oBufLast, &i));
fModified = 0;
}
}
fScreen = TRUE;
break;
case 0x7F: /* ALT Delete (Delete Marked Block) */
if (pEdit->oBufMark < EMPTY) {
deleteData ();
fScreen = TRUE;
}
break;
default:
break;
}
}
else if (key & 0x0300) { /* CTRL key is down */
}
/* Standard editing keys including LF */
else if (((b >= 0x20) && (b <= 0x7E)) || (b == 0x0D)) {
coordCursor_oBuf ();
if (b == 0x20)
b = pEdit->bSpace;
if (b == 0x0D)
b = 0x0A;
/* Don't overwrite CR */
if (pBuff[pEdit->oBufInsert] == 0x0A)
fSpecInsert = TRUE;
if (!(putInBuf (b, fOvertype, fSpecInsert)))
Beep();
findCursor ();
fScreen = TRUE;
}
else if (key & 0x0C00) { /* SHIFT key is down & NOT letter keys */
switch (b) {
case 0x04: /* SHIFT Right */
if (pEdit->iCol < pEdit->iColMax - 5)
pEdit->iCol += 5;
else
if (pEdit->iCol < pEdit->iColMax)
pEdit->iCol++;
break;
case 0x03: /* SHIFT Left */
if (pEdit->iCol > pEdit->iColMin + 5)
pEdit->iCol -= 5;
else
if (pEdit->iCol > pEdit->iColMin)
pEdit->iCol--;
break;
default:
break;
}
}
else { /* Unshifted editing keys */
switch (b) {
case 0x08: /* Backspace */
if (pEdit->oBufLast) {
coordCursor_oBuf ();
if (pEdit->oBufInsert) {
pEdit->oBufInsert = pEdit->oBufInsert - 1;
if (!fOvertype) {
CopyData(pBuff,
pBuffWork,
pEdit->oBufLast+1);
CopyData(&pBuffWork[pEdit->oBufInsert+1],
&pBuff[pEdit->oBufInsert],
pEdit->oBufLast-pEdit->oBufInsert);
pBuff[pEdit->oBufLast] = 0;
pEdit->oBufLast = pEdit->oBufLast - 1;
if ((pEdit->oBufMark == pEdit->oBufBound) &&
(pEdit->oBufMark == pEdit->oBufInsert))
nullMarkBound ();
if (pEdit->oBufMark < EMPTY) {
if (pEdit->oBufInsert <= pEdit->oBufMark)
pEdit->oBufMark--;
if (pEdit->oBufInsert <= pEdit->oBufBound)
pEdit->oBufBound--;
}
}
}
if (pEdit->oBufInsert < pEdit->oBufLine0)
pEdit->oBufLine0 = findPrevLine (pEdit->oBufLine0);
fScreen = TRUE;
fModified = TRUE;
}
break;
case 0x06: /* Home - Cursor to BOL */
pEdit->iCol = pEdit->iColMin;
break;
case 0x09: /* Tab */
if (pEdit->oBufLast + pEdit->iTabNorm < pEdit->iBufMax) {
coordCursor_oBuf ();
j = pEdit->iTabNorm - (pEdit->iCol % pEdit->iTabNorm);
for (i=1; i <=j; i++)
putInBuf (pEdit->bSpace, FALSE, FALSE);
fScreen = TRUE;
}
break;
case 0x10: /* F2 -- UNMARK BLOCK */
nullMarkBound ();
break;
case 0x11: /* F3 -- Begin Block */
if (pEdit->oBufLast > 0) {
coordCursor_oBuf ();
pEdit->oBufMark = pEdit->oBufInsert;
i = pEdit->iLine;
if (pEdit->oBufMark >= pEdit->Line[i+1])
pEdit->oBufMark = pEdit->oBufMark - 1;
if (pEdit->oBufMark == pEdit->oBufLast)
pEdit->oBufMark = pEdit->oBufLast - 1;
pEdit->oBufBound = pEdit->oBufMark;
fScreen = TRUE;
}
break;
case 0x12: /* F4 -- End Block */
if (pEdit->oBufMark < EMPTY) {
coordCursor_oBuf ();
pEdit->oBufBound = pEdit->oBufInsert;
i = pEdit->iLine;
if (pEdit->oBufBound >= pEdit->Line[i+1])
pEdit->oBufBound--;
if (pEdit->oBufBound == pEdit->oBufLast)
pEdit->oBufBound = pEdit->oBufLast - 1;
fScreen = TRUE;
}
break;
case 0x17: /* F9 - MOVE */
coordCursor_oBuf ();
moveData ();
if (pEdit->oBufInsert < pEdit->oBufLine0)
pEdit->oBufLine0 = pEdit->oBufInsert;
fScreen = TRUE;
break;
case 0x18: /* F10 - COPY */
coordCursor_oBuf ();
CopyIt ();
coordCursor_oBuf ();
fScreen = TRUE;
break;
case 0x0C: /* Page Down */
coordCursor_oBuf ();
i = pEdit->iRowMax;
while ((pEdit->Line[i] == EMPTY) && (i > pEdit->iRowMin))
i--;
pEdit->oBufLine0 = pEdit->Line[i];
/*always keep onScreen*/
if (pEdit->oBufInsert < pEdit->oBufLine0)
pEdit->oBufInsert = pEdit->oBufLine0;
pEdit->iLine = pEdit->iRowMin;
pEdit->iCol = pEdit->iColMin;
fScreen = TRUE;
break;
case 0x05: /* Page Up */
if (pEdit->oBufLine0) {
coordCursor_oBuf ();
j = pEdit->iRowMax - pEdit->iRowMin;
i = pEdit->oBufLine0;
k = pEdit->iLine; /*fix for scrolling when iLine=iRowMax */
do {
i = findPrevLine (i);
j--;
k--;
}
while ((j > 0) && (i > 0));
pEdit->oBufLine0 = i;
/*fix for scroll when iLine=iRowMax*/
if (pEdit->iLine == pEdit->iRowMax)
pEdit->oBufInsert = pEdit->Line[k];
/*keep on screen*/
i = pEdit->iRowMax;
if (pEdit->oBufInsert >= pEdit->Line[i+1])
pEdit->oBufInsert = pEdit->Line[i];
fScreen = TRUE;
}
break;
case 0x01: /* Up */
if (pEdit->iLine > pEdit->iRowMin) {
pEdit->iLine--;
} else { /* scroll screen down if we can */
i = pEdit->oBufLine0;
if (i > 0) {
i = findPrevLine (i);
pEdit->oBufLine0 = i;
pEdit->oBufInsert = i;
fScreen = TRUE;
}
}
break;
case 0x02: /* Down */
i = pEdit->iLine;
if ((pEdit->Line[i+1] < EMPTY) && /*Down Arrow*/
(i < pEdit->iRowMax)) {
pEdit->iLine++;
}
else { /* ELSE scroll screen UP if we can */
i = pEdit->iRowMax;
if (pEdit->Line[i+1] < EMPTY) {
pEdit->oBufInsert = pEdit->Line[i+1];
i = pEdit->iCol;
j = pEdit->iLine;
coordCursor_oBuf ();
pEdit->iCol = i;
pEdit->iLine = j;
fScreen = TRUE;
}
}
break;
case 0x03: /* Left */
if (pEdit->iCol > pEdit->iColMin) { /*Left Arrow*/
pEdit->iCol--;
}
break;
case 0x04: /* Right */
if (pEdit->iCol < pEdit->iColMax) {
pEdit->iCol++;
}
break;
case 0x0E: /* Insert */
if (fOvertype)
fOvertype = FALSE;
else fOvertype = TRUE;
break;
case 0x7F: /* Delete */
coordCursor_oBuf ();
if ((pEdit->oBufLast) &&
(pEdit->oBufLast > pEdit->oBufInsert)) {
CopyData(pBuff,
pBuffWork,
pEdit->oBufLast+1);
CopyData(&pBuffWork[pEdit->oBufInsert+1],
&pBuff[pEdit->oBufInsert],
pEdit->oBufLast-pEdit->oBufInsert);
pBuff[pEdit->oBufLast] = 0;
pEdit->oBufLast--;
if ((pEdit->oBufInsert == pEdit->oBufMark) &&
(pEdit->oBufMark == pEdit->oBufBound))
nullMarkBound ();
if (pEdit->oBufMark < EMPTY) {
if (pEdit->oBufInsert < pEdit->oBufMark)
pEdit->oBufMark--;
if (pEdit->oBufInsert < pEdit->oBufBound)
pEdit->oBufBound--;
if (pEdit->oBufMark == pEdit->oBufLast)
pEdit->oBufMark--;
if (pEdit->oBufBound == pEdit->oBufLast)
pEdit->oBufBound--;
}
fScreen = TRUE;
fModified = TRUE;
}
break;
case 0x1B: /* Escape */
fDone = TRUE;
break;
default:
break;
}
}
} /* Not fDone */
for (i=pEdit->iRowMin; i <=pEdit->iRowMax; i++)
PutVidAttrs (pEdit->iColMin, i, pEdit->sLine+1, 0); /* REM buffer column */
if (fh) {
if (pEdit->fVisible) /* fix visible characters */
for (i=0; i <=pEdit->iBufMax; i++)
if (pBuff[i] == 0x07)
pBuff[i] = 0x20;
pBuff[pEdit->oBufLast] = 0;
if (fModified) {
erc = CheckErc(6, SetFileLFA(fh, 0));
if (!erc)
erc = CheckErc(5, SetFileSize(fh,pEdit->oBufLast));
if (!erc)
erc = CheckErc(3, WriteBytes (fh, pBuf1, pEdit->oBufLast, &i));
fModified = 0;
}
CloseFile(fh);
cbFilename = 0;
}
*pbExitRet = b;
return;
}
void main(void)
{
long key;
ClrScr();
fh = 0;
pEdit = &EdRec;
erc = AllocPage(16, &pBuf1);
erc = AllocPage(16, &pBuf2);
pEdit->pBuf = pBuf1;
pEdit->pBufWork = pBuf2;
pEdit->iBufMax = 65535; /*sBuf - 1 */
pEdit->iColMin = 0; /*Screen coordinates*/
pEdit->iColMax = 79;
pEdit->iRowMin = 1;
pEdit->iRowMax = 23;
pEdit->sLine = 80; /* iColMax-iColMin+1 */
pEdit->bSpace = 0x20;
pEdit->fVisible = FALSE;
pEdit->iAttrMark = MARKVID; /* Rev Vid*/
pEdit->iAttrNorm = EDVID; /* Rev Vid Half Bright */
pEdit->iTabNorm = 4; /* Tabs every 4th column */
pEdit->oBufLine0 = 0; /* oBufLine0 */
pEdit->iCol = 0; /* cursor, 0..sLine-1 */
pEdit->iLine = 0; /* cursor, 0..cLines-1 */
pEdit->oBufInsert = 0; /* offset of next char in */
pEdit->oBufLast = 0; /* offset+1 of last char */
pEdit->oBufMark = EMPTY;
pEdit->oBufBound = EMPTY;
SetNormVid(NORMVID);
EditSFA (&b);
ExitJob(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -