summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <git@matthiasm.com>2021-12-08 18:55:34 +0100
committerMatthias Melcher <git@matthiasm.com>2021-12-08 18:55:44 +0100
commit17c8f73a88037fbe5efde00ff7d44a2f6f51e494 (patch)
treecda28ef9b4a9c49fffdc179cbc37f81de6eebae8
parent16dae3ea063ae134b8b87ca199575e904dfbb7d4 (diff)
STR 3460.C: Code Properties remembers the editor's scroll bar position.
-rw-r--r--fluid/CodeEditor.h2
-rw-r--r--fluid/Fl_Function_Type.cxx15
-rw-r--r--fluid/Fl_Function_Type.h2
-rw-r--r--src/Fl_Text_Display.cxx11
4 files changed, 21 insertions, 9 deletions
diff --git a/fluid/CodeEditor.h b/fluid/CodeEditor.h
index d30f1b680..dcbb292e1 100644
--- a/fluid/CodeEditor.h
+++ b/fluid/CodeEditor.h
@@ -51,6 +51,8 @@ public:
~CodeEditor();
int top_line() { return get_absolute_top_line_number(); }
void textsize(Fl_Fontsize s);
+ int scroll_row() { return mTopLineNum; }
+ int scroll_col() { return mHorizOffset; }
};
// ---- CodeViewer declaration
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx
index f8b9cd276..0f6c3ba34 100644
--- a/fluid/Fl_Function_Type.cxx
+++ b/fluid/Fl_Function_Type.cxx
@@ -529,10 +529,6 @@ int Fl_Function_Type::has_signature(const char *rtype, const char *sig) const {
This node manages an arbitrary block of code inside a function that will
be written into the source code file. Fl_Code_Block has no comment field.
However, the first line of code will be shown in the widget browser.
-
- \todo Fl_Code_Block stores the cursor position in text editor, but it does not
- store the view position (scrollbars). Make sure that we can always see
- the cursor when opening the dialog. (it's not stored in the .fl file)
*/
/// Prototype for code to be used by the factory.
@@ -541,9 +537,11 @@ Fl_Code_Type Fl_Code_type;
/**
Constructor.
*/
-Fl_Code_Type::Fl_Code_Type() {
- cursor_position_ = 0;
-}
+Fl_Code_Type::Fl_Code_Type() :
+ cursor_position_(0),
+ code_input_scroll_row(0),
+ code_input_scroll_col(0)
+{}
/**
Make a new code node.
@@ -580,6 +578,7 @@ void Fl_Code_Type::open() {
const char *text = name();
code_input->buffer()->text( text ? text : "" );
code_input->insert_position(cursor_position_);
+ code_input->scroll(code_input_scroll_row, code_input_scroll_col);
code_panel->show();
const char* message = 0;
for (;;) { // repeat as long as there are errors
@@ -597,6 +596,8 @@ void Fl_Code_Type::open() {
break;
}
cursor_position_ = code_input->insert_position();
+ code_input_scroll_row = code_input->scroll_row();
+ code_input_scroll_col = code_input->scroll_col();
BREAK2:
code_panel->hide();
}
diff --git a/fluid/Fl_Function_Type.h b/fluid/Fl_Function_Type.h
index d5b0087c0..7a6ac818e 100644
--- a/fluid/Fl_Function_Type.h
+++ b/fluid/Fl_Function_Type.h
@@ -72,6 +72,8 @@ public:
class Fl_Code_Type : public Fl_Type {
ExternalCodeEditor editor_;
int cursor_position_;
+ int code_input_scroll_row;
+ int code_input_scroll_col;
public:
Fl_Code_Type();
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index a9cfcdfaf..731d7a94e 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -4146,18 +4146,25 @@ int Fl_Text_Display::handle(int event) {
/*
Convert an x pixel position into a column number.
+ The width of a column is calculated as the average width of a few
+ representative characters, giving a good estimate for proportional fonts.
+ This method does not take the possition of the scroll bars into account.
+ \param[in] x offset to the left edge of the text in FLTK units.
+ \return approximation to the corresponding text column
+ \see col_to_x()
*/
-double Fl_Text_Display::x_to_col(double y) const
+double Fl_Text_Display::x_to_col(double x) const
{
if (!mColumnScale) {
mColumnScale = string_width("Mitg", 4, 'A') / 4.0;
}
- return (y/mColumnScale)+0.5;
+ return (x/mColumnScale)+0.5;
}
/**
Convert a column number into an x pixel position.
+ \see x_to_col()
*/
double Fl_Text_Display::col_to_x(double col) const
{