/** * \brief the function select entirely the document */ static void select_entirely_doc( ScintillaObject *sci ) { gint size_buf = sci_get_length(sci); sci_set_selection_start( sci , 0 ) ; sci_set_selection_end( sci , size_buf ) ; }
static PyObject * ZenEditor_replace_content(ZenEditor *self, PyObject *args) { PyObject *result; gint sel_start = -1, sel_end = -1, ph_pos; gchar *text, *ph, *tmp, *tmp2; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); if (PyArg_ParseTuple(args, "s|ii", &text, &sel_start, &sel_end)) { tmp = ZenEditor_replace_caret_placeholder(self->caret_placeholder, text, &ph_pos); tmp2 = ZenEditor_replace_range(tmp); g_free(tmp); if (sel_start == -1 && sel_end == -1) { /* replace whole editor content */ sci_set_text(sci, tmp2); } else if (sel_start != -1 && sel_end == -1) { /* insert text at sel_start */ sci_insert_text(sci, sel_start, tmp2); } else if (sel_start != -1 && sel_end != -1) { /* replace from sel_start to sel_end */ sci_set_selection_start(sci, sel_start); sci_set_selection_end(sci, sel_end); sci_replace_sel(sci, tmp2); } else { dbgf("Invalid arguments were supplied."); g_free(tmp2); Py_RETURN_NONE; } g_free(tmp2); /* Move cursor to first placeholder position, if found */ if (ph_pos > -1) sci_set_current_position(sci, sel_start + ph_pos, TRUE); } else { if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } } Py_RETURN_NONE; }
void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); ScintillaObject *sci; gchar *text; gboolean keep_sel = TRUE; g_return_if_fail(doc != NULL); sci = doc->editor->sci; if (! sci_has_selection(sci)) { keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD); keep_sel = FALSE; } /* either we already had a selection or we created one for current word */ if (sci_has_selection(sci)) { gchar *result = NULL; gint cmd = SCI_LOWERCASE; gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0); text = sci_get_selection_contents(sci); if (utils_str_has_upper(text)) { if (rectsel) cmd = SCI_LOWERCASE; else result = g_utf8_strdown(text, -1); } else { if (rectsel) cmd = SCI_UPPERCASE; else result = g_utf8_strup(text, -1); } if (result != NULL) { sci_replace_sel(sci, result); g_free(result); if (keep_sel) sci_set_selection_start(sci, sci_get_current_position(sci) - strlen(text)); } else sci_send_command(sci, cmd); g_free(text); } }
static PyObject * Scintilla_set_selection_start(Scintilla *self, PyObject *args, PyObject *kwargs) { gint pos; static gchar *kwlist[] = { "pos", NULL }; SCI_RET_IF_FAIL(self); if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &pos)) sci_set_selection_start(self->sci, pos); Py_RETURN_NONE; }
static gboolean editor_notify_cb(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data) { gint lexer, pos, style, min, size; gchar sel[512]; if (nt->nmhdr.code == SCN_CHARADDED && nt->ch == '>') { lexer = sci_get_lexer(editor->sci); if (lexer == SCLEX_XML || lexer == SCLEX_HTML) { pos = sci_get_current_position(editor->sci); style = sci_get_style_at(editor->sci, pos); if ((style <= SCE_H_XCCOMMENT || highlighting_is_string_style(lexer, style)) && !highlighting_is_comment_style(lexer, style)) { CompletionInfo c; InputInfo i; /* Grab the last 512 characters or so */ min = pos - sizeof(sel); if (min < 0) min = 0; size = pos - min; sci_get_text_range(editor->sci, min, pos, sel); if (get_completion(editor, sel, size, &c, &i)) { /* Remove typed opening tag */ sci_set_selection_start(editor->sci, min + i.tag_start); sci_set_selection_end(editor->sci, pos); sci_replace_sel(editor->sci, ""); pos -= (size - i.tag_start); /* pos has changed while deleting */ /* Insert the completion */ editor_insert_snippet(editor, pos, c.completion); sci_scroll_caret(editor->sci); g_free((gchar *)c.completion); return TRUE; } } } } return FALSE; }
static PyObject * ZenEditor_create_selection(ZenEditor *self, PyObject *args) { gint sel_start = -1, sel_end = -1; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); if (PyArg_ParseTuple(args, "i|i", &sel_start, &sel_end)) { if (sel_end == -1) sci_set_current_position(sci, sel_start, TRUE); else { sci_set_selection_start(sci, sel_start); sci_set_selection_end(sci, sel_end); } } Py_RETURN_NONE; }
static void menu_suggestion_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata) { const gchar *sugg; gint startword, endword; ScintillaObject *sci = clickinfo.doc->editor->sci; g_return_if_fail(clickinfo.doc != NULL && clickinfo.pos != -1); startword = scintilla_send_message(sci, SCI_WORDSTARTPOSITION, clickinfo.pos, 0); endword = scintilla_send_message(sci, SCI_WORDENDPOSITION, clickinfo.pos, 0); if (startword != endword) { gchar *word; sci_set_selection_start(sci, startword); sci_set_selection_end(sci, endword); /* retrieve the old text */ word = g_malloc(sci_get_selected_text_length(sci) + 1); sci_get_selected_text(sci, word); /* retrieve the new text */ sugg = gtk_label_get_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem)))); /* replace the misspelled word with the chosen suggestion */ sci_replace_sel(sci, sugg); /* store the replacement for future checks */ sc_speller_store_replacement(word, sugg); /* remove indicator */ sci_indicator_clear(sci, startword, endword - startword); g_free(word); } }
static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_before; gint txt_len; gint startpos; gint endpos; gint startline; gint endline; gint line_iter; gint linepos; gint linelen; gint startcol; gint endcol; gint i; gint n_spaces; gchar *spaces; ScintillaObject *sci; /* get a pointer to the scintilla object */ sci = document_get_current()->editor->sci; if (sci_has_selection(sci)){ startpos = sci_get_selection_start(sci); endpos = sci_get_selection_end(sci); /* sanity check -- we dont care which way the block was selected */ if(startpos > endpos){ i = endpos; endpos = startpos; startpos = i; } startline = sci_get_line_from_position(sci, startpos); /* Setting also start point for 1st line */ linepos = sci_get_position_from_line(sci, startline); endline = sci_get_line_from_position(sci, endpos); /* normal mode */ if(startline == endline){ /* get the text in question */ txt_len = endpos - startpos; txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_before = sci_get_char_at(sci, startpos - 1); /* set up new text buf */ (void) g_sprintf(txt, "%s%c", txt_i, char_before); /* start undo */ sci_start_undo_action(sci); /* put the new text in */ sci_set_selection_start(sci, startpos - 1); sci_replace_sel(sci, txt); /* select the right bit again */ sci_set_selection_start(sci, startpos - 1); sci_set_selection_end(sci, endpos - 1); /* end undo */ sci_end_undo_action(sci); g_free(txt); g_free(txt_i); } /* rectangle mode (we hope!) */ else{ startcol = sci_get_col_from_position(sci, startpos); endcol = sci_get_col_from_position(sci, endpos); /* return early for the trivial case */ if(startcol == 0 || startcol == endcol){ return; } /* start undo */ sci_start_undo_action(sci); for(line_iter = startline; line_iter <= endline; line_iter++){ linepos = sci_get_position_from_line(sci, line_iter); linelen = sci_get_line_length(sci, line_iter); /* do we need to do something */ if(linelen >= startcol - 1 ){ /* if between the two columns */ /* pad to the end first */ if(linelen <= endcol){ /* bung in some spaces -- sorry, I dont like tabs */ n_spaces = endcol - linelen + 1; spaces = g_malloc(sizeof(gchar) * (n_spaces + 1)); for(i = 0; i < n_spaces; i++){ spaces[i] = ' '; } spaces[i] = '\0'; sci_insert_text(sci, linepos + linelen - 1, spaces); g_free(spaces); } /* now move the text itself */ sci_set_selection_mode(sci, 0); sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol); txt_len = sci_get_selected_text_length(sci); txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_before = sci_get_char_at(sci, linepos + startcol - 1); /* set up new text buf */ (void) g_sprintf(txt, "%s%c", txt_i, char_before); /* put the new text in */ sci_set_selection_start(sci, linepos + startcol - 1); sci_replace_sel(sci, txt); g_free(txt); g_free(txt_i); } } /* put the selection box back */ /* here we rely upon the last result of linepos */ sci_set_selection_mode(sci, 1); sci_set_selection_start(sci, startpos - 1); sci_set_selection_end(sci, linepos + endcol - 1); /* end undo action */ sci_end_undo_action(sci); } } }
static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_after; gint txt_len; gint startpos; gint endpos; gint startline; gint endline; gint line_iter; gint linepos; gint linelen; gint startcol; gint endcol; gint i; ScintillaObject *sci; /* get a pointer to the scintilla object */ sci = document_get_current()->editor->sci; if (sci_has_selection(sci)){ startpos = sci_get_selection_start(sci); endpos = sci_get_selection_end(sci); /* sanity check -- we dont care which way the block was selected */ if(startpos > endpos){ i = endpos; endpos = startpos; startpos = i; } startline = sci_get_line_from_position(sci, startpos); linepos = sci_get_position_from_line(sci, startline); endline = sci_get_line_from_position(sci, endpos); /* normal mode */ if(startline == endline){ /* get the text in question */ txt_len = endpos - startpos; txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_after = sci_get_char_at(sci, endpos); /* set up new text buf */ (void) g_sprintf(txt, "%c%s", char_after, txt_i); /* start undo */ sci_start_undo_action(sci); /* put the new text in */ sci_set_selection_end(sci, endpos + 1); sci_replace_sel(sci, txt); /* select the right bit again */ sci_set_selection_start(sci, startpos + 1); sci_set_selection_end(sci, endpos + 1); /* end undo */ sci_end_undo_action(sci); g_free(txt); g_free(txt_i); } /* rectangle mode (we hope!) */ else{ startcol = sci_get_col_from_position(sci, startpos); endcol = sci_get_col_from_position(sci, endpos); /* start undo */ sci_start_undo_action(sci); for(line_iter = startline; line_iter <= endline; line_iter++){ linepos = sci_get_position_from_line(sci, line_iter); linelen = sci_get_line_length(sci, line_iter); /* do we need to do something */ if(linelen >= startcol - 1 ){ /* if between the two columns or at the end */ /* add in a space */ if(linelen <= endcol || linelen - 1 == endcol){ txt = g_malloc(sizeof(gchar) * 2); sprintf(txt, " "); sci_insert_text(sci, linepos + startcol, txt); g_free(txt); } else{ /* move the text itself */ sci_set_selection_mode(sci, 0); sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol); txt_len = sci_get_selected_text_length(sci); txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_after = sci_get_char_at(sci, linepos + endcol); /* set up new text buf */ (void) g_sprintf(txt, "%c%s", char_after, txt_i); /* put the new text in */ sci_set_selection_end(sci, linepos + endcol + 1); sci_replace_sel(sci, txt); g_free(txt); g_free(txt_i); } } } /* put the selection box back */ /* here we rely upon the last result of linepos */ sci_set_selection_mode(sci, 1); sci_set_selection_start(sci, startpos + 1); sci_set_selection_end(sci, linepos + endcol + 1); /* end undo action */ sci_end_undo_action(sci); } } }