Changeset b8b742e in mainline


Ignore:
Timestamp:
2012-08-15T23:03:55Z (12 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b224a3e, c8444d8
Parents:
a44abb3e
Message:

Add Go To Line functionality for edit (use Ctrl+L).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/edit.c

    ra44abb3e rb8b742e  
    126126static int file_save_range(char const *fname, spt_t const *spos,
    127127    spt_t const *epos);
    128 static char *filename_prompt(char const *prompt, char const *init_value);
    129128static char *range_get_str(spt_t const *spos, spt_t const *epos);
     129
     130static char *prompt(char const *prompt, char const *init_value);
    130131
    131132static void pane_text_display(void);
     
    142143static void caret_move_word_left(void);
    143144static void caret_move_word_right(void);
     145static void caret_move_to_line(int row);
     146static void caret_go_to_line_ask(void);
    144147
    145148static bool selection_active(void);
     
    404407                caret_move_word_left();
    405408                break;
     409        case KC_L:
     410                caret_go_to_line_ask();
     411                break;
    406412        default:
    407413                break;
     
    520526        char *fname;
    521527       
    522         fname = filename_prompt("Save As", old_fname);
     528        fname = prompt("Save As", old_fname);
    523529        if (fname == NULL) {
    524530                status_display("Save cancelled.");
     
    535541}
    536542
    537 /** Ask for a file name. */
    538 static char *filename_prompt(char const *prompt, char const *init_value)
     543/** Ask for a string. */
     544static char *prompt(char const *prompt, char const *init_value)
    539545{
    540546        kbd_event_t ev;
     
    10781084}
    10791085
     1086/** Change the caret position to a beginning of a given line
     1087 */
     1088static void caret_move_to_line(int row)
     1089{
     1090        spt_t pt;
     1091        coord_t coord;
     1092        int num_rows;
     1093
     1094        tag_get_pt(&pane.caret_pos, &pt);
     1095        spt_get_coord(&pt, &coord);
     1096        coord.row = row;
     1097        coord.column = 1;
     1098
     1099        /* Clamp coordinates. */
     1100        if (coord.row < 1) coord.row = 1;
     1101        sheet_get_num_rows(&doc.sh, &num_rows);
     1102        if (coord.row > num_rows) coord.row = num_rows;
     1103
     1104        /*
     1105         * Select the point before the character at the designated
     1106         * coordinates. The character can be wider than one cell (e.g. tab).
     1107         */
     1108        sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt);
     1109        sheet_remove_tag(&doc.sh, &pane.caret_pos);
     1110        sheet_place_tag(&doc.sh, &pt, &pane.caret_pos);
     1111
     1112        /* Set the new value for @c ideal_column. */
     1113        spt_get_coord(&pt, &coord);
     1114        pane.ideal_column = coord.column;
     1115
     1116        caret_update();
     1117}
     1118
     1119/** Ask for line and go to it. */
     1120static void caret_go_to_line_ask(void)
     1121{
     1122        char *sline;
     1123       
     1124        sline = prompt("Go to line", "");
     1125        if (sline == NULL) {
     1126                status_display("Go to line cancelled.");
     1127                return;
     1128        }
     1129       
     1130        char *endptr;
     1131        int line = strtol(sline, &endptr, 10);
     1132        if (*endptr != '\0') {
     1133                status_display("Invalid number entered.");
     1134                return;
     1135        }
     1136       
     1137        caret_move_to_line(line);
     1138}
     1139
     1140
    10801141/** Check for non-empty selection. */
    10811142static bool selection_active(void)
Note: See TracChangeset for help on using the changeset viewer.