📄 test.c
字号:
if (p->text[pos].ch == '{')
if (!indentlevel) {
while (pos && p->text[pos-1].ch != '\n')
pos -- ;
while (isspace(p->text[pos].ch))
pos ++ ;
eospos = pos ;
break ;
} else
indentlevel-- ;
else if (p->text[pos].ch == '}')
indentlevel++ ;
pos-- ;
}
n = curcol(p,p->text,eospos) ;
p->selstartcharpos = lsolpos ;
p->selendcharpos = leospos ;
Replace(hwnd,p,"",0) ;
while (n >= p->tabs) {
inserttab(hwnd,p) ;
n-=p->tabs;
}
while (n--)
insertchar(hwnd,p,' ') ;
p->selstartcharpos = ++p->selendcharpos ; // skip past '}'
}
p->inserting = oldinsert ;
}
void SelectIndent(HWND hwnd, EDITDATA *p, int insert)
{
int olds = p->selstartcharpos ;
int olde = p->selendcharpos ;
int start = p->selstartcharpos ;
int end = p->selendcharpos ;
int oldinsert = p->inserting ;
UNDO *u ;
if (start == end)
return ;
if (end < start) {
start = p->selendcharpos ;
end = p->selstartcharpos ;
}
if (end && p->text[end-1].ch == '\n')
end-- ;
p->inserting = TRUE ;
if (insert)
u = undo_insertindent(p) ;
else
u = undo_deleteindent(p) ;
while (start && p->text[start-1].ch != '\n')
start-- ;
while (p->text[end].ch && p->text[end].ch != '\n')
end++ ;
p->undoing++ ;
olds = start ;
while (start < end) {
if (insert) {
p->selstartcharpos = p->selendcharpos = start ;
inserttab(hwnd,p) ;
end += p->selstartcharpos - start ;
} else {
if (isspace(p->text[start].ch) && p->text[start].ch != '\n') {
int count = 0 ;
if (p->text[start+count].ch == ' ')
while (++count < p->tabs)
if (p->text[start+count].ch != ' ')
break ;
else
count++ ;
else
count++ ;
p->selstartcharpos = start ;
p->selendcharpos = start + count ;
Replace(hwnd,p,"",0) ;
end -= count ;
}
}
while (p->text[start].ch && p->text[start].ch != '\n')
start++ ;
if (p->text[start].ch)
start++ ;
}
p->undoing-- ;
p->selendcharpos = end ;
p->selstartcharpos = olds ;
p->inserting = oldinsert ;
if (u) {
u->postselend = end ;
u->postselstart = olds ;
}
InvalidateRect(hwnd,0,0);
}
void DeletePound(HWND hwnd, EDITDATA *p)
{
int n,m ;
if (p->colorize != COLORIZE_C)
return ;
if (editFlags & AUTO_FORMAT)
return ;
if (p->text[p->selstartcharpos-1].ch != '#')
return ;
n = p->selstartcharpos-1 ;
while (n && p->text[n-1].ch != '\n')
n-- ;
m = n ;
while (isspace(p->text[m].ch) && p->text[m].ch != '#')
m++ ;
if (p->text[m].ch != '#')
return ;
p->selstartcharpos = n ;
p->selendcharpos = m ;
Replace(hwnd,p,"",0) ;
p->selstartcharpos = p->selendcharpos = n+1 ;
ScrollCaretIntoView(hwnd,p) ;
}
void DeletePercent(HWND hwnd, EDITDATA *p)
{
int n,m ;
if (p->colorize != COLORIZE_ASM)
return ;
if (editFlags & AUTO_FORMAT)
return ;
if (p->text[p->selstartcharpos-1].ch != '%')
return ;
n = p->selstartcharpos-1 ;
while (n && p->text[n-1].ch != '\n')
n-- ;
m = n ;
while (isspace(p->text[m].ch) && p->text[m].ch != '%')
m++ ;
if (p->text[m].ch != '%')
return ;
p->selstartcharpos = n ;
p->selendcharpos = m ;
Replace(hwnd,p,"",0) ;
p->selstartcharpos = p->selendcharpos = n+1 ;
ScrollCaretIntoView(hwnd,p) ;
}
/**********************************************************************
* go backwards to the last tab position
**********************************************************************/
void backtab(HWND hwnd, EDITDATA *p)
{
int pos = p->selstartcharpos, col=0,col2 ;
if (pos) {
if (p->text[pos-1].ch =='\t')
p->selstartcharpos-- ;
else {
int sol ;
if (p->text[pos].ch == '\n')
pos-- ;
while (pos) {
if (p->text[pos].ch == '\n') {
pos++ ;
break ;
}
pos-- ;
}
sol = pos ;
while (pos != p->selstartcharpos) {
if (p->text[pos].ch == '\t') {
col = col + p->tabs ;
col /= p->tabs ;
col *= p->tabs ;
} else
col++ ;
pos++ ;
}
col2 = col - 1 ;
col2 /= p->tabs ;
col2 *= p->tabs ;
col = 0 ;
while (col < col2) {
if (p->text[pos].ch == '\t') {
col = col + p->tabs ;
col /= p->tabs ;
col *= p->tabs ;
} else
col++ ;
sol++ ;
}
p->selstartcharpos = sol ;
}
Replace(hwnd,p,"",0) ;
}
}
/**********************************************************************
* removecr cuts a CR/LF pair
**********************************************************************/
void removecr(HWND hwnd, EDITDATA *p,int utype)
{
#ifdef OLD_EDIT_FORMAT
int del = 1 ;
#else
int del = 0 ;
#endif
int sel = SelLine(p,p->selstartcharpos) ;
#ifdef OLD_EDIT_FORMAT
if (p->text[p->selstartcharpos].ch == '\r' && p->text[p->selstartcharpos+1].ch == '\n')
#else
if (p->text[p->selstartcharpos].ch == '\n')
#endif
del ++,sel++;
SendMessage(GetParent(hwnd),EN_LINECHANGE,sel,-1) ;
undo_deletechar(p,CRLF_DUMMY,utype) ;
memcpy(p->text + p->selstartcharpos, p->text + p->selstartcharpos + del, (p->textlen-p->selstartcharpos-del+1) * sizeof(INTERNAL_CHAR)) ;
p->textlen -= del ;
SendUpdate(hwnd) ;
p->sendchangeonpaint = TRUE ;
VScrollLen(hwnd, -1, FALSE) ;
VScrollPos(hwnd,-1,FALSE) ;
}
/**********************************************************************
* removechar cuts a character from the text (delete or back arrow)
**********************************************************************/
void removechar(HWND hwnd, EDITDATA *p, int utype)
{
if (p->inserting && p->selstartcharpos != p->selendcharpos) {
Replace(hwnd,p,"",0) ;
ScrollCaretIntoView(hwnd,p) ;
} else {
int del ;
if (p->selstartcharpos == p->textlen)
return ;
#ifdef OLD_EDIT_FORMAT
if (p->text[p->selstartcharpos].ch == '\r' || p->text[p->selstartcharpos].ch == '\n') {
#else
if (p->text[p->selstartcharpos].ch == '\n') {
#endif
removecr(hwnd,p,utype) ;
ScrollCaretIntoView(hwnd,p) ;
drawline(hwnd,p,p->selstartcharpos) ;
} else {
undo_deletechar(p,p->text[p->selstartcharpos].ch,utype) ;
memcpy(p->text + p->selstartcharpos, p->text + p->selstartcharpos + 1, (p->textlen-p->selstartcharpos) * sizeof(INTERNAL_CHAR)) ;
p->textlen-- ;
drawline(hwnd,p,p->selstartcharpos) ;
}
}
p->selendcharpos = p->selstartcharpos ;
}
/**********************************************************************
* SelToClipboard copies the current selection to the clipboard
**********************************************************************/
void SelToClipboard(HWND hwnd, EDITDATA *p)
{
int start,end ;
if (p->selendcharpos-p->selstartcharpos < 0 ) {
end = p->selstartcharpos;
start= p->selendcharpos ;
} else {
end = p->selendcharpos;
start= p->selstartcharpos ;
}
if (end == start)
return ;
if (OpenClipboard(hwnd)) {
HGLOBAL glmem = GlobalAlloc(GMEM_DDESHARE + GMEM_MOVEABLE,end-start+1) ;
if (glmem != NULL) {
char *data = GlobalLock(glmem) ;
int i ;
for (i=start; i < end; i++)
data[i-start] = p->text[i].ch ;
data[i-start]= 0 ;
GlobalUnlock(data) ;
EmptyClipboard() ;
SetClipboardData(CF_TEXT,glmem) ;
}
CloseClipboard() ;
}
}
/**********************************************************************
* ClipboardToSel pastes the clipboard into the text
**********************************************************************/
void ClipboardToSel(HWND hwnd, EDITDATA *p)
{
if (!IsClipboardFormatAvailable(CF_TEXT))
return ;
if (OpenClipboard(hwnd)) {
HANDLE clh = GetClipboardData(CF_TEXT) ;
char *data = GlobalLock(clh) ;
int l = GlobalSize(clh) ;
if (l) {
char *mem = malloc(l) ;
if (mem) {
memcpy(mem,data,l) ;
mem[l-1] = 0 ;
if (mem[0]) {
Replace(hwnd,p,mem,strlen(mem)) ;
ScrollCaretIntoView(hwnd,p) ;
if (p->colorize)
FormatBufferFromScratch(p->text,p->selstartcharpos-1,p->selendcharpos+1,p->colorize) ;
SendUpdate(hwnd) ;
p->sendchangeonpaint = TRUE ;
p->selendcharpos = p->selstartcharpos = p->selstartcharpos + strlen(mem) ;
MoveCaret(hwnd,p) ;
InvalidateRect(hwnd,0,0) ;
}
free(mem) ;
}
}
GlobalUnlock(data) ;
CloseClipboard() ;
}
}
/**********************************************************************
* upline scrolls the display down one line
**********************************************************************/
void upline(HWND hwnd, EDITDATA *p, int lines)
{
RECT r ;
int ilines = lines ;
int curline ;
int pos,oldsel ;
int col,index = 0 ;
if (p->selecting)
pos = p->selendcharpos ;
else
pos = p->selstartcharpos ;
// oldsel = pos ;
col = p->updowncol ;
if (lines > 0) {
while (lines && pos < p->textlen) {
if (p->text[pos].ch == '\n')
lines-- ;
pos++ ;
}
} else {
#ifndef OLD_EDIT_FORMAT
if (pos)
pos-- ;
#endif
while (lines && pos) {
if (p->text[pos].ch == '\n')
lines++ ;
pos-- ;
}
while (pos) {
if (p->text[pos].ch == '\n') {
pos++ ;
break ;
}
pos-- ;
}
}
while (index < col && pos < p->textlen && p->text[pos].ch != '\n') {
if (p->text[pos].ch == '\t') {
index += p->tabs ;
index = (index/p->tabs) * p->tabs ;
} else
index++ ;
pos ++ ;
}
#ifdef OLD_EDIT_FORMAT
if (pos && p->text[pos].ch == '\n')
pos -- ;
#endif
if (!p->selecting)
p->selendcharpos = p->selstartcharpos = pos ;
else
p->selendcharpos = pos ;
ScrollCaretIntoView(hwnd,p) ;
}
/**********************************************************************
* FillEditBackground puts the background on those parts of a line that
* need it
**********************************************************************/
void FillEditBackground(HDC dc, RECT *r, HBRUSH sel, EDITDATA *p, int tabcol,int pos)
{
RECT r1 ;
int start,end ;
int tabwidth ;
int col = 0 ;
if (p->selstartcharpos <= p->selendcharpos) {
start = p->selstartcharpos ;
end = p->selendcharpos ;
} else {
start = p->selendcharpos ;
end = p->selstartcharpos ;
}
if (start == end || pos > end) {
FillRect(dc,r,p->hbrBackground) ;
return ;
}
r1 = *r ;
tabwidth = p->tabs * p->txtFontWidth ;
r1.right = 0 ;
if (pos < start) {
#ifdef OLD_EDIT_FORMAT
while (pos < start && pos < p->textlen && p->text[pos].ch != '\r' && p->text[pos].ch != '\n') {
#else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -