View Issue Details

IDProjectCategoryView StatusLast Update
0001901Far ManagerEditorpublic2011-10-12 07:38
Reporter2useven10 Assigned To2useven10  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version3.0 
Fixed in Version3.0 
Summary0001901: Текущая позиция не сохраняется при переключении между View/Edit по F6 на неоднобайтных кодировках
DescriptionРедактор считает позицию в символах, вьювер в байтах (теперь и в юникоде тоже).
Результат стартовая позиция 'едет'. Вьювер может неверно показывать символы,
лечится через AdjustFilePos, но от дребезга позиции не спасает.
Steps To ReproduceОткрыть utf-8 файл во вьювере (FarRus.hlf)
сместиь позицию за строку содержащую русский текст.
F6 F6
Additional Informationпоместил в раздел редактора, т.к. для вьювера единственный способ посчитать символы - прочесть весь файл от начала, что пожалуй не годится.
TagsNo tags attached.
Build2217

Activities

2useven10

2011-10-04 08:48

developer  

F6.diff (3,577 bytes)   
Index: editor.hpp
===================================================================
--- editor.hpp	(revision 6749)
+++ editor.hpp	(working copy)
@@ -283,7 +283,7 @@
 
 	public:
 
-		void SetCacheParams(EditorPosCache &pc);
+		void SetCacheParams(EditorPosCache &pc, bool count_bom=false);
 		void GetCacheParams(EditorPosCache &pc);
 
 		bool SetCodePage(UINT codepage);  //BUGBUG
@@ -301,7 +301,7 @@
 		BOOL IsFileModified() const;
 		BOOL IsFileChanged() const;
 		void SetTitle(const wchar_t *Title);
-		long GetCurPos();
+		long GetCurPos( bool file_pos=false, bool add_bom=false );
 		int EditorControl(int Command,void *Param);
 		void SetHostFileEditor(FileEditor *Editor) {HostFileEditor=Editor;};
 		static void SetReplaceMode(int Mode);
Index: editor.cpp
===================================================================
--- editor.cpp	(revision 6749)
+++ editor.cpp	(working copy)
@@ -4807,21 +4807,35 @@
 }
 
 // ���������� � FileEditor
-long Editor::GetCurPos()
+long Editor::GetCurPos( bool file_pos, bool add_bom )
 {
 	Edit *CurPtr=TopList;
 	long TotalSize=0;
+	int mult = 1, bom = 0;
+	if ( file_pos ) {
+		if ( m_codepage == CP_UNICODE || m_codepage == CP_REVERSEBOM ) {
+			mult = 2;
+			if ( add_bom ) bom += 2;
+		}
+		else if ( m_codepage == CP_UTF8 ) {
+			mult = -1;
+			if ( add_bom ) bom += 3;
+		}
+	}
 
 	while (CurPtr!=TopScreen)
 	{
 		const wchar_t *SaveStr,*EndSeq;
 		int Length;
 		CurPtr->GetBinaryString(&SaveStr,&EndSeq,Length);
-		TotalSize+=Length+StrLength(EndSeq);
+		if ( mult > 0 )
+			TotalSize += Length + StrLength(EndSeq);
+		else
+			TotalSize -= WideCharToMultiByte(CP_UTF8,0,SaveStr,Length,nullptr,0,nullptr,nullptr)+StrLength(EndSeq);
 		CurPtr=CurPtr->m_next;
 	}
 
-	return(TotalSize);
+	return TotalSize * mult + bom;
 }
 
 
@@ -6903,7 +6917,7 @@
 }
 
 
-void Editor::SetCacheParams(EditorPosCache &pc)
+void Editor::SetCacheParams(EditorPosCache &pc, bool count_bom)
 {
 	bool translateTabs=false;
 	SavePos=pc.bm;
@@ -6913,14 +6927,29 @@
 	{
 		Edit *CurPtr=TopList;
 		long TotalSize=0;
+		bool utf8 = false;
 
+		if ( m_codepage == CP_UNICODE || m_codepage == CP_REVERSEBOM ) {
+			StartChar /= 2;
+			if ( count_bom )
+				--StartChar;
+		}
+		else if ( m_codepage == CP_UTF8 ) {
+			utf8 = true;
+			if ( count_bom )
+				StartChar -= 3;
+		}
+
 		while (CurPtr && CurPtr->m_next)
 		{
 			const wchar_t *SaveStr,*EndSeq;
 			int Length;
 			CurPtr->GetBinaryString(&SaveStr,&EndSeq,Length);
-			TotalSize+=Length+StrLength(EndSeq);
+			if ( utf8 )
+				Length = WideCharToMultiByte(CP_UTF8,0, SaveStr,Length, nullptr,0, nullptr,nullptr);
 
+			TotalSize += Length + StrLength(EndSeq);
+
 			if (TotalSize > StartChar)
 				break;
 
Index: fileedit.cpp
===================================================================
--- fileedit.cpp	(revision 6749)
+++ fileedit.cpp	(working copy)
@@ -902,7 +902,7 @@
 
 				if (!FirstSave || m_editor->IsFileChanged() || apiGetFileAttributes(strFullFileName)!=INVALID_FILE_ATTRIBUTES)
 				{
-					long FilePos=m_editor->GetCurPos();
+					long FilePos=m_editor->GetCurPos(true, m_bAddSignature);
 
 					/* $ 01.02.2001 IS
 					   ! �������� ��� � ��������� �������� ����� �����, � �� ���������
@@ -1642,7 +1642,7 @@
 
 	EditFile.Close();
 	//if ( bCached )
-	m_editor->SetCacheParams(pc);
+	m_editor->SetCacheParams(pc, m_bAddSignature);
 	SysErrorCode=GetLastError();
 	apiGetFindDataEx(Name, FileInfo);
 	EditorGetFileAttributes(Name);
F6.diff (3,577 bytes)   

2useven10

2011-10-04 08:49

developer   bugnote:0007826

F6.diff - фикс

Denis

2011-10-04 10:49

reporter  

F6.for.Far2.bis.diff (5,646 bytes)   
diff --git a/Far2bis/editor.cpp b/Far2bis/editor.cpp
index e6a8803..af7732b 100644
--- a/Far2bis/editor.cpp
+++ b/Far2bis/editor.cpp
@@ -4715,21 +4715,35 @@ BOOL Editor::IsFileModified() const
 }
 
 // ���������� � FileEditor
-long Editor::GetCurPos()
+long Editor::GetCurPos(bool file_pos, bool add_bom)
 {
 	Edit *CurPtr=TopList;
 	long TotalSize=0;
+	int mult = 1, bom = 0;
+	if ( file_pos ) {
+		if ( m_codepage == CP_UNICODE || m_codepage == CP_REVERSEBOM ) {
+			mult = 2;
+			if ( add_bom ) bom += 2;
+		}
+		else if ( m_codepage == CP_UTF8 ) {
+			mult = -1;
+			if ( add_bom ) bom += 3;
+		}
+	}
 
 	while (CurPtr!=TopScreen)
 	{
 		const wchar_t *SaveStr,*EndSeq;
 		int Length;
 		CurPtr->GetBinaryString(&SaveStr,&EndSeq,Length);
-		TotalSize+=Length+StrLength(EndSeq);
+		if ( mult > 0 )
+			TotalSize += Length + StrLength(EndSeq);
+		else
+			TotalSize -= WideCharToMultiByte(CP_UTF8,0,SaveStr,Length,nullptr,0,nullptr,nullptr)+StrLength(EndSeq);
 		CurPtr=CurPtr->m_next;
 	}
 
-	return(TotalSize);
+	return TotalSize * mult + bom;
 }
 
 
@@ -6797,7 +6811,7 @@ Edit *Editor::InsertString(const wchar_t *lpwszStr, int nLength, Edit *pAfter, i
 }
 
 
-void Editor::SetCacheParams(EditorCacheParams *pp)
+void Editor::SetCacheParams(EditorCacheParams *pp, bool count_bom)
 {
 	bool translateTabs=false;
 	SavePos=pp->SavePos;
@@ -6807,13 +6821,28 @@ void Editor::SetCacheParams(EditorCacheParams *pp)
 	{
 		Edit *CurPtr=TopList;
 		long TotalSize=0;
+		bool utf8 = false;
+ 
+		if ( m_codepage == CP_UNICODE || m_codepage == CP_REVERSEBOM ) {
+			StartChar /= 2;
+			if ( count_bom )
+				--StartChar;
+		}
+		else if ( m_codepage == CP_UTF8 ) {
+			utf8 = true;
+			if ( count_bom )
+				StartChar -= 3;
+		}
 
 		while (CurPtr && CurPtr->m_next)
 		{
 			const wchar_t *SaveStr,*EndSeq;
 			int Length;
 			CurPtr->GetBinaryString(&SaveStr,&EndSeq,Length);
-			TotalSize+=Length+StrLength(EndSeq);
+			if ( utf8 )
+				Length = WideCharToMultiByte(CP_UTF8,0, SaveStr,Length, nullptr, 0, nullptr,nullptr);
+ 
+			TotalSize += Length + StrLength(EndSeq);
 
 			if (TotalSize > StartChar)
 				break;
diff --git a/Far2bis/editor.hpp b/Far2bis/editor.hpp
index 7c04096..10aa3a6 100644
--- a/Far2bis/editor.hpp
+++ b/Far2bis/editor.hpp
@@ -303,7 +303,7 @@ class Editor:public ScreenObject
 
 	public:
 
-		void SetCacheParams(EditorCacheParams *pp);
+		void SetCacheParams(EditorCacheParams *pp, bool count_bom=false);
 		void GetCacheParams(EditorCacheParams *pp);
 
 		bool SetCodePage(UINT codepage);  //BUGBUG
@@ -321,7 +321,7 @@ class Editor:public ScreenObject
 		BOOL IsFileModified() const;
 		BOOL IsFileChanged() const;
 		void SetTitle(const wchar_t *Title);
-		long GetCurPos();
+		long GetCurPos(bool file_pos=false, bool add_bom=false);
 		int EditorControl(int Command,void *Param);
 		void SetHostFileEditor(FileEditor *Editor) {HostFileEditor=Editor;};
 		static void SetReplaceMode(int Mode);
diff --git a/Far2bis/farversion.m4 b/Far2bis/farversion.m4
index fb940c4..26c5657 100644
--- a/Far2bis/farversion.m4
+++ b/Far2bis/farversion.m4
@@ -10,7 +10,7 @@ m4_define(BLD_MONTH,m4_substr(DATE,3,2))m4_dnl
 m4_define(BLD_DAY,m4_substr(DATE,0,2))m4_dnl
 m4_define(COPYRIGHTYEARS,m4_ifelse(`2000',BLD_YEAR,`2000',`2000-'BLD_YEAR))m4_dnl
 m4_define(MAKEFULLVERSION,`m4_ifelse(
-`',$1,`MAJOR.MINOR (build BUILD bis21.6) $2',
+`',$1,`MAJOR.MINOR (build BUILD bis21.8) $2',
 `RC',$1,`MAJOR.MINOR RC (build BUILD) $2',
 `alpha',$1,`MAJOR.MINOR alpha (build BUILD) $2',
 `beta',$1,`MAJOR.MINOR beta (build BUILD) $2',
diff --git a/Far2bis/fileedit.cpp b/Far2bis/fileedit.cpp
index 8a84b07..accc236 100644
--- a/Far2bis/fileedit.cpp
+++ b/Far2bis/fileedit.cpp
@@ -911,7 +911,7 @@ int FileEditor::ReProcessKey(int Key,int CalledFromControl)
 
 				if (!FirstSave || m_editor->IsFileChanged() || apiGetFileAttributes(strFullFileName)!=INVALID_FILE_ATTRIBUTES)
 				{
-					long FilePos=m_editor->GetCurPos();
+					long FilePos=m_editor->GetCurPos(true, m_bAddSignature);
 
 					/* $ 01.02.2001 IS
 					   ! �������� ��� � ��������� �������� ����� �����, � �� ���������
@@ -1626,7 +1626,7 @@ int FileEditor::LoadFile(const wchar_t *Name,int &UserBreak)
 
 	EditFile.Close();
 	//if ( bCached )
-	m_editor->SetCacheParams(&cp);
+	m_editor->SetCacheParams(&cp, m_bAddSignature);
 	SysErrorCode=GetLastError();
 	apiGetFindDataEx(Name, FileInfo);
 	EditorGetFileAttributes(Name);
diff --git a/Far2bis/viewer.cpp b/Far2bis/viewer.cpp
index 7bdbc50..c1d60ca 100644
--- a/Far2bis/viewer.cpp
+++ b/Far2bis/viewer.cpp
@@ -1449,6 +1449,7 @@ int Viewer::ProcessKey(int Key)
 		{
 			VM.CodePage = VM.CodePage==GetOEMCP() ? GetACP() : GetOEMCP();
 			lcache_ready = false;
+      AdjustFilePos();
 			ChangeViewKeyBar();
 			Show();
 			CodePageChangedByUser=TRUE;
@@ -1457,8 +1458,6 @@ int Viewer::ProcessKey(int Key)
 		case KEY_SHIFTF8:
 		{
 			UINT nCodePage = SelectCodePage(VM.CodePage, true, true, false, true);
-			lcache_ready = false;
-
 			if (nCodePage != static_cast<UINT>(-1))
 			{
 				if (nCodePage == (CP_AUTODETECT & 0xffff))
@@ -1471,7 +1470,8 @@ int Viewer::ProcessKey(int Key)
 				}
 				CodePageChangedByUser=TRUE;
 				VM.CodePage=nCodePage;
-				SetFileSize();
+				lcache_ready = false;
+				AdjustFilePos();
 				ChangeViewKeyBar();
 				Show();
 			}
@@ -3386,6 +3386,7 @@ void Viewer::SetTitle(const wchar_t *Title)
 void Viewer::SetFilePos(__int64 Pos)
 {
 	FilePos=Pos;
+  AdjustFilePos();
 };
 
 void Viewer::SetPluginData(const wchar_t *PluginData)
-- 
1.7.6.msysgit.0

F6.for.Far2.bis.diff (5,646 bytes)   

Denis

2011-10-04 10:49

reporter   bugnote:0007827

Добавил тот же фикс, но для Far2.bis

2useven10

2011-10-11 10:21

developer   bugnote:0007863

build 2217

Issue History

Date Modified Username Field Change
2011-10-03 19:33 2useven10 New Issue
2011-10-04 08:48 2useven10 File Added: F6.diff
2011-10-04 08:49 2useven10 Note Added: 0007826
2011-10-04 10:49 Denis File Added: F6.for.Far2.bis.diff
2011-10-04 10:49 Denis Note Added: 0007827
2011-10-11 10:21 2useven10 Note Added: 0007863
2011-10-11 10:21 2useven10 Assigned To => 2useven10
2011-10-11 10:21 2useven10 Status new => feedback
2011-10-12 07:37 2useven10 Status feedback => resolved
2011-10-12 07:38 2useven10 Build => 2217
2011-10-12 07:38 2useven10 Status resolved => closed
2011-10-12 07:38 2useven10 Resolution open => fixed
2011-10-12 07:38 2useven10 Fixed in Version => 3.0