[Ttssh2-commit] [5371] 左右マージン上に2バイト文字が有った時にスクロール等でゴミが出るのを修正。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2013年 8月 27日 (火) 03:34:42 JST


Revision: 5371
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5371
Author:   doda
Date:     2013-08-27 03:34:39 +0900 (Tue, 27 Aug 2013)
Log Message:
-----------
左右マージン上に2バイト文字が有った時にスクロール等でゴミが出るのを修正。
# 見逃せないバグなので、入れさせてください

Modified Paths:
--------------
    trunk/teraterm/teraterm/buffer.c

-------------- next part --------------
Modified: trunk/teraterm/teraterm/buffer.c
===================================================================
--- trunk/teraterm/teraterm/buffer.c	2013-08-25 05:32:50 UTC (rev 5370)
+++ trunk/teraterm/teraterm/buffer.c	2013-08-26 18:34:39 UTC (rev 5371)
@@ -557,11 +557,41 @@
 	}
 }
 
+void EraseKanjiOnLRMargin(LONG ptr, int count)
+{
+	int i;
+	LONG pos;
+
+	if (count < 1)
+		return;
+
+	for (i=0; i<count; i++) {
+		pos = ptr + CursorLeftM-1;
+		if (CursorLeftM>0 && (AttrBuff[pos] & AttrKanji)) {
+			CodeBuff[pos] = 0x20;
+			AttrBuff[pos] &= ~AttrKanji;
+			pos++;
+			CodeBuff[pos] = 0x20;
+			AttrBuff[pos] &= ~AttrKanji;
+		}
+		pos = ptr + CursorRightM;
+		if (CursorRightM < NumOfColumns-1 && (AttrBuff[pos] & AttrKanji)) {
+			CodeBuff[pos] = 0x20;
+			AttrBuff[pos] &= ~AttrKanji;
+			pos++;
+			CodeBuff[pos] = 0x20;
+			AttrBuff[pos] &= ~AttrKanji;
+		}
+		ptr = NextLinePtr(ptr);
+	}
+}
+
 void BuffInsertSpace(int Count)
 // Insert space characters at the current position
 //   Count: Number of characters to be inserted
 {
 	int MoveLen;
+	int extr=0;
 
 	if (CursorX < CursorLeftM || CursorX > CursorRightM)
 		return;
@@ -571,6 +601,12 @@
 	if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8)
 		EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
 
+	if (CursorRightM < NumOfColumns-1 && (AttrLine[CursorRightM] & AttrKanji)) {
+		CodeLine[CursorRightM+1] = 0x20;
+		AttrLine[CursorRightM+1] &= ~AttrKanji;
+		extr = 1;
+	}
+
 	if (Count > CursorRightM + 1 - CursorX)
 		Count = CursorRightM + 1 - CursorX;
 
@@ -592,12 +628,9 @@
 	if ((AttrLine[CursorRightM] & AttrKanji) != 0) {
 		/* then delete it */
 		CodeLine[CursorRightM] = 0x20;
-		AttrLine[CursorRightM] = AttrDefault;
-		AttrLine2[CursorRightM] = CurCharAttr.Attr2;
-		AttrLineFG[CursorRightM] = CurCharAttr.Fore;
-		AttrLineBG[CursorRightM] = CurCharAttr.Back;
+		AttrLine[CursorRightM] &= ~AttrKanji;
 	}
-	BuffUpdateRect(CursorX, CursorY, CursorRightM, CursorY);
+	BuffUpdateRect(CursorX, CursorY, CursorRightM+extr, CursorY);
 }
 
 void BuffEraseCurToEnd()
@@ -671,10 +704,18 @@
 //   YEnd: bottom line number of scroll region (screen coordinate)
 {
 	int i, linelen;
+	int extl=0, extr=0;
 	LONG SrcPtr, DestPtr;
 
 	BuffUpdateScroll();
 
+	if (CursorLeftM > 0)
+		extl = 1;
+	if (CursorRightM < NumOfColumns-1)
+		extr = 1;
+	if (extl || extr)
+		EraseKanjiOnLRMargin(GetLinePtr(PageStart+CursorY), YEnd-CursorY+1);
+
 	SrcPtr = GetLinePtr(PageStart+YEnd-Count) + CursorLeftM;
 	DestPtr = GetLinePtr(PageStart+YEnd) + CursorLeftM;
 	linelen = CursorRightM - CursorLeftM + 1;
@@ -697,7 +738,7 @@
 	}
 
 	if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1 || !DispInsertLines(Count, YEnd)) {
-		BuffUpdateRect(CursorLeftM, CursorY, CursorRightM, YEnd);
+		BuffUpdateRect(CursorLeftM-extl, CursorY, CursorRightM+extr, YEnd);
 	}
 }
 
@@ -746,10 +787,18 @@
 //   YEnd: bottom line number of scroll region (screen coordinate)
 {
 	int i, linelen;
+	int extl=0, extr=0;
 	LONG SrcPtr, DestPtr;
 
 	BuffUpdateScroll();
 
+	if (CursorLeftM > 0)
+		extl = 1;
+	if (CursorRightM < NumOfColumns-1)
+		extr = 1;
+	if (extl || extr)
+		EraseKanjiOnLRMargin(GetLinePtr(PageStart+CursorY), YEnd-CursorY+1);
+
 	SrcPtr = GetLinePtr(PageStart+CursorY+Count) + (LONG)CursorLeftM;
 	DestPtr = GetLinePtr(PageStart+CursorY) + (LONG)CursorLeftM;
 	linelen = CursorRightM - CursorLeftM + 1;
@@ -772,7 +821,7 @@
 	}
 
 	if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1 || ! DispDeleteLines(Count,YEnd)) {
-		BuffUpdateRect(CursorLeftM, CursorY, CursorRightM, YEnd);
+		BuffUpdateRect(CursorLeftM-extl, CursorY, CursorRightM+extr, YEnd);
 	}
 }
 
@@ -781,6 +830,7 @@
 //   Count: number of characters to be deleted
 {
 	int MoveLen;
+	int extr=0;
 
 	if (CursorX < CursorLeftM || CursorX > CursorRightM)
 		return;
@@ -792,6 +842,14 @@
 		EraseKanji(1); /* if cursor on right half... */
 	}
 
+	if (CursorRightM < NumOfColumns-1 && (AttrLine[CursorRightM] & AttrKanji)) {
+		CodeLine[CursorRightM] = 0x20;
+		AttrLine[CursorRightM] &= ~AttrKanji;
+		CodeLine[CursorRightM+1] = 0x20;
+		AttrLine[CursorRightM+1] &= ~AttrKanji;
+		extr = 1;
+	}
+
 	if (Count > CursorRightM + 1 - CursorX)
 		Count = CursorRightM + 1 - CursorX;
 
@@ -810,7 +868,7 @@
 	memset(&(AttrLineFG[CursorX + MoveLen]), CurCharAttr.Fore, Count);
 	memset(&(AttrLineBG[CursorX + MoveLen]), CurCharAttr.Back, Count);
 
-	BuffUpdateRect(CursorX, CursorY, CursorRightM, CursorY);
+	BuffUpdateRect(CursorX, CursorY, CursorRightM+extr, CursorY);
 }
 
 void BuffEraseChars(int Count)
@@ -1597,6 +1655,7 @@
 //   Insert: Insert flag
 {
 	int XStart, LineEnd, MoveLen;
+	int extr = 0;
 
 #ifndef NO_COPYLINE_FIX
 	if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
@@ -1617,6 +1676,14 @@
 		else
 			LineEnd = CursorRightM;
 
+		if (LineEnd < NumOfColumns - 1 && (AttrLine[LineEnd] & AttrKanji)) {
+			CodeLine[LineEnd] = 0x20;
+			AttrLine[LineEnd] &= ~AttrKanji;
+			CodeLine[LineEnd+1] = 0x20;
+			AttrLine[LineEnd+1] &= ~AttrKanji;
+			extr = 1;
+		}
+
 		MoveLen = LineEnd - CursorX;
 		if (MoveLen > 0) {
 			memmove(&CodeLine[CursorX+1], &CodeLine[CursorX], MoveLen);
@@ -1651,7 +1718,7 @@
 			XStart = StrChangeStart;
 		}
 		StrChangeCount = 0;
-		BuffUpdateRect(XStart, CursorY, LineEnd, CursorY);
+		BuffUpdateRect(XStart, CursorY, LineEnd+extr, CursorY);
 	}
 	else {
 		CodeLine[CursorX] = b;
@@ -1677,6 +1744,7 @@
 //   Insert: Insert flag
 {
 	int XStart, LineEnd, MoveLen;
+	int extr = 0;
 
 #ifndef NO_COPYLINE_FIX
 	if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
@@ -1692,6 +1760,14 @@
 		else
 			LineEnd = CursorRightM;
 
+		if (LineEnd < NumOfColumns - 1 && (AttrLine[LineEnd] & AttrKanji)) {
+			CodeLine[LineEnd] = 0x20;
+			AttrLine[LineEnd] &= ~AttrKanji;
+			CodeLine[LineEnd+1] = 0x20;
+			AttrLine[LineEnd+1] &= ~AttrKanji;
+			extr = 1;
+		}
+
 		MoveLen = LineEnd - CursorX - 1;
 		if (MoveLen > 0) {
 			memmove(&CodeLine[CursorX+2], &CodeLine[CursorX], MoveLen);
@@ -1735,7 +1811,7 @@
 			XStart = StrChangeStart;
 		}
 		StrChangeCount = 0;
-		BuffUpdateRect(XStart, CursorY, LineEnd, CursorY);
+		BuffUpdateRect(XStart, CursorY, LineEnd+extr, CursorY);
 	}
 	else {
 		CodeLine[CursorX] = HIBYTE(w);
@@ -2003,11 +2079,19 @@
 void ScrollUp1Line()
 {
 	int i, linelen;
+	int extl=0, extr=0;
 	LONG SrcPtr, DestPtr;
 
 	if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
 		UpdateStr();
 
+		if (CursorLeftM > 0)
+			extl = 1;
+		if (CursorRightM < NumOfColumns-1)
+			extr = 1;
+		if (extl || extr)
+			EraseKanjiOnLRMargin(GetLinePtr(PageStart+CursorTop), CursorBottom-CursorTop+1);
+
 		linelen = CursorRightM - CursorLeftM + 1;
 		DestPtr = GetLinePtr(PageStart+CursorBottom) + CursorLeftM;
 		for (i = CursorBottom-1 ; i >= CursorTop ; i--) {
@@ -2026,7 +2110,7 @@
 		memset(&(AttrBuffBG[SrcPtr]), CurCharAttr.Back, linelen);
 
 		if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1)
-			BuffUpdateRect(CursorLeftM, CursorTop, CursorRightM, CursorBottom);
+			BuffUpdateRect(CursorLeftM-extl, CursorTop, CursorRightM+extr, CursorBottom);
 		else
 			DispScrollNLines(CursorTop, CursorBottom, -1);
 	}
@@ -2035,6 +2119,7 @@
 void BuffScrollNLines(int n)
 {
 	int i, linelen;
+	int extl=0, extr=0;
 	LONG SrcPtr, DestPtr;
 
 	if (n<1) {
@@ -2070,6 +2155,13 @@
 	}
 
 	if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
+		if (CursorLeftM > 0)
+			extl = 1;
+		if (CursorRightM < NumOfColumns-1)
+			extr = 1;
+		if (extl || extr)
+			EraseKanjiOnLRMargin(GetLinePtr(PageStart+CursorTop), CursorBottom-CursorTop+1);
+
 		linelen = CursorRightM - CursorLeftM + 1;
 		DestPtr = GetLinePtr(PageStart+CursorTop) + (LONG)CursorLeftM;
 		if (n<CursorBottom-CursorTop+1) {
@@ -2096,7 +2188,7 @@
 			DestPtr = NextLinePtr(DestPtr);
 		}
 		if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1)
-			BuffUpdateRect(CursorLeftM, CursorTop, CursorRightM, CursorBottom);
+			BuffUpdateRect(CursorLeftM-extl, CursorTop, CursorRightM+extr, CursorBottom);
 		else
 			DispScrollNLines(CursorTop, CursorBottom, n);
 	}
@@ -2104,6 +2196,7 @@
 
 void BuffRegionScrollUpNLines(int n) {
 	int i, linelen;
+	int extl=0, extr=0;
 	LONG SrcPtr, DestPtr;
 
 	if (n<1) {
@@ -2123,6 +2216,13 @@
 		}
 	}
 	else {
+		if (CursorLeftM > 0)
+			extl = 1;
+		if (CursorRightM < NumOfColumns-1)
+			extr = 1;
+		if (extl || extr)
+			EraseKanjiOnLRMargin(GetLinePtr(PageStart+CursorTop), CursorBottom-CursorTop+1);
+
 		DestPtr = GetLinePtr(PageStart+CursorTop) + CursorLeftM;
 		linelen = CursorRightM - CursorLeftM + 1;
 		if (n < CursorBottom - CursorTop + 1) {
@@ -2150,7 +2250,7 @@
 		}
 
 		if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1) {
-			BuffUpdateRect(CursorLeftM, CursorTop, CursorRightM, CursorBottom);
+			BuffUpdateRect(CursorLeftM-extl, CursorTop, CursorRightM+extr, CursorBottom);
 		}
 		else {
 			DispScrollNLines(CursorTop, CursorBottom, n);
@@ -2160,6 +2260,7 @@
 
 void BuffRegionScrollDownNLines(int n) {
 	int i, linelen;
+	int extl=0, extr=0;
 	LONG SrcPtr, DestPtr;
 
 	if (n<1) {
@@ -2167,6 +2268,13 @@
 	}
 	UpdateStr();
 
+	if (CursorLeftM > 0)
+		extl = 1;
+	if (CursorRightM < NumOfColumns-1)
+		extr = 1;
+	if (extl || extr)
+		EraseKanjiOnLRMargin(GetLinePtr(PageStart+CursorTop), CursorBottom-CursorTop+1);
+
 	DestPtr = GetLinePtr(PageStart+CursorBottom) + CursorLeftM;
 	linelen = CursorRightM - CursorLeftM + 1;
 	if (n < CursorBottom - CursorTop + 1) {
@@ -2194,7 +2302,7 @@
 	}
 
 	if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1) {
-		BuffUpdateRect(CursorLeftM, CursorTop, CursorRightM, CursorBottom);
+		BuffUpdateRect(CursorLeftM-extl, CursorTop, CursorRightM+extr, CursorBottom);
 	}
 	else {
 		DispScrollNLines(CursorTop, CursorBottom, -n);



Ttssh2-commit メーリングリストの案内
Back to archive index