epasveer / seer

Seer - a gui frontend to gdb
GNU General Public License v3.0
2.11k stars 67 forks source link

Tab characters in source files are not handled correctly. #120

Closed epasveer closed 1 year ago

epasveer commented 1 year ago

Take this source file that contains tabs. (The arrows are tab characters).

  1 #include <string>
  2 #include <iostream>
  3 
  4 void function1 (const std::string& message);
  5 
  6 int main (int argc, char** argv) {
  7 
  8 →   // 123456789 123456789 123456789
  9 →   // →2 4→6→   1→ 4  7→   2 4→6
 10 
 11 →   int j = 0;
 12 
 13 →   for (int i=0; i<argc; i++) {
 14 →   →   std::cout << "XX: "
 15 →   →   →   << i
 16 →   →   →   << " "
 17 →   →   →   << argv[i]
 18 →   →   →   << std::endl;
 19 →   }
 20 
 21 →   std::string message = "Hello, Tabs!";
 22 
 23 →   j++;
 24 
 25 →   function1(message);
 26 
 27 →   return 0;
 28 }
 29 

Seer uses QPlainTextEdit widget, which has a default tab width of 80 pixels. The rendered text is way off.

image

Setting QPlainTextEdit's 'tabStopSpacing' to 4 mono-spaced characters is close, but not good enough. Probably doesn't handle where the tab occurs in the string.

image

Applying an 'expandtab' function on the string will replace tabs with the correct spacing, no matter where the tab occurs. This requires a 'tab size' parameter in the Editor settings dialog.

image

epasveer commented 1 year ago

Couldn't get QPlainTextEdit::setTabStopDistance() to work. QFont::setLetterSpacing() didn't help either.

In fact, all things failed to render tab characters correctly. Most notably, if one uses the scrollwheel to zoom in or out of a QPlainTextEdit, the tab stops really get messed up.

epasveer commented 1 year ago

Adding a Seer::expandTab(QString) function to expand any tabs works well. But I'm surprised QPlainTextEdit is so broken.

epasveer commented 1 year ago

Added a 'tab size' option to the Editor config page.

image