STR 3460.C: Code Properties remembers the editor's scroll bar position.
This commit is contained in:
parent
16dae3ea06
commit
17c8f73a88
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user