Skip to content

Commit b9ce745

Browse files
author
Kasper Peeters
committed
Fix keybindings, bump version.
1 parent 050a51f commit b9ce745

File tree

4 files changed

+72
-15
lines changed

4 files changed

+72
-15
lines changed

.github/workflows/tarball.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
name: Tarball
55

6-
# on:
7-
# release:
8-
# types: [created]
6+
on:
7+
release:
8+
types: [created]
99

10-
on: [push]
10+
# on: [push]
1111

1212
jobs:
1313
build:

cmake/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(CADABRA_VERSION_MAJOR 2)
22
set(CADABRA_VERSION_MINOR 5)
3-
set(CADABRA_VERSION_PATCH 6)
3+
set(CADABRA_VERSION_PATCH 8)
44
set(CADABRA_VERSION_TWEAK 0)
55
set(CADABRA_VERSION_SEM ${CADABRA_VERSION_MAJOR}.${CADABRA_VERSION_MINOR}.${CADABRA_VERSION_PATCH})
66
set(COPYRIGHT_YEARS "2001-2024")

frontend/gtkmm/CodeInput.cc

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@ void CodeInput::init(const Prefs& prefs)
7070
edit.set_left_margin(20);
7171
// if(gtk_get_minor_version()<11 || gtk_get_minor_version()>=14)
7272

73+
// Determine the width of a tab.
74+
auto layout = Pango::Layout::create(edit.get_pango_context());
75+
Pango::Rectangle logical_rect;
76+
layout->set_text(" ");
77+
int space_width, space_height;
78+
layout->get_pixel_size(space_width, space_height);
79+
80+
// Set 10 tab stops, each 3 spaces wide.
81+
edit.set_monospace(true);
7382
edit.set_accepts_tab(true);
7483
Pango::TabArray tabs(10);
75-
// FIXME: use character width measured, instead of '8', or at least
76-
// understand how Pango units are supposed to work.
7784
for(int i=0; i<10; ++i)
78-
tabs.set_tab(i, Pango::TAB_LEFT, 4*8*i);
85+
tabs.set_tab(i, Pango::TAB_LEFT, 3*space_width*i);
7986
edit.set_tabs(tabs);
8087

8188
edit.signal_button_press_event().connect(sigc::mem_fun(this, &CodeInput::handle_button_press), false);
@@ -509,12 +516,14 @@ bool CodeInput::exp_input_tv::on_key_press_event(GdkEventKey* event)
509516
bool is_shift_return = get_editable() && event->keyval==GDK_KEY_Return && (event->state&Gdk::SHIFT_MASK);
510517
// bool is_shift_tab = get_editable() && event->keyval==GDK_KEY_Tab && (event->state&Gdk::SHIFT_MASK);
511518
bool is_tab = get_editable() && event->keyval==GDK_KEY_Tab;
519+
bool is_ctrl_k = get_editable() && event->keyval==GDK_KEY_k && (event->state&Gdk::CONTROL_MASK);
520+
bool is_ctrl_a = get_editable() && event->keyval==GDK_KEY_a && (event->state&Gdk::CONTROL_MASK);
521+
bool is_ctrl_e = get_editable() && event->keyval==GDK_KEY_e && (event->state&Gdk::CONTROL_MASK);
522+
512523
bool retval=false;
513-
// std::cerr << event->keyval << ", " << event->state << " pressed, focus = " << has_focus()
514-
// << ", editable = " << get_editable() << ", is_shift_return = " << is_shift_return << std::endl;
524+
// std::cerr << event->keyval << ", " << event->state << " pressed, focus = " << has_focus()
525+
// << ", editable = " << get_editable() << ", is_shift_return = " << is_shift_return << std::endl;
515526

516-
if(!is_shift_return && !is_tab)
517-
retval=Gtk::TextView::on_key_press_event(event);
518527

519528
Glib::RefPtr<Gtk::TextBuffer> textbuf=get_buffer();
520529

@@ -523,7 +532,7 @@ bool CodeInput::exp_input_tv::on_key_press_event(GdkEventKey* event)
523532
content_execute(datacell);
524533
return true;
525534
}
526-
if(is_tab) {
535+
else if(is_tab) {
527536
// Only complete if the last character is not whitespace.
528537

529538
Glib::RefPtr<Gtk::TextBuffer::Mark> ins = get_buffer()->get_insert();
@@ -535,6 +544,43 @@ bool CodeInput::exp_input_tv::on_key_press_event(GdkEventKey* event)
535544
else
536545
retval=Gtk::TextView::on_key_press_event(event);
537546
}
547+
else if(is_ctrl_a) {
548+
Glib::RefPtr<Gtk::TextBuffer::Mark> ins = get_buffer()->get_insert();
549+
Gtk::TextBuffer::iterator iter=textbuf->get_iter_at_mark(ins);
550+
iter.set_line(iter.get_line());
551+
textbuf->place_cursor(iter);
552+
return true;
553+
}
554+
else if(is_ctrl_e) {
555+
Glib::RefPtr<Gtk::TextBuffer::Mark> ins = get_buffer()->get_insert();
556+
Gtk::TextBuffer::iterator iter=textbuf->get_iter_at_mark(ins);
557+
iter.forward_to_line_end();
558+
textbuf->place_cursor(iter);
559+
return true;
560+
}
561+
else if(is_ctrl_k) {
562+
Glib::RefPtr<Gtk::TextBuffer::Mark> ins = get_buffer()->get_insert();
563+
Gtk::TextBuffer::iterator iter=textbuf->get_iter_at_mark(ins);
564+
auto line = iter.get_line();
565+
Gtk::TextBuffer::iterator line_start = iter;
566+
Gtk::TextBuffer::iterator line_end = iter;
567+
568+
// Move to the start and end of the line
569+
line_start.set_line(iter.get_line()); // Move to the beginning of the line
570+
line_end.forward_to_line_end(); // Move to the end of the line
571+
572+
// Include the newline character if it exists (non-last line)
573+
if (!line_end.is_end())
574+
line_end.forward_char();
575+
576+
// Delete the text between line_start and line_end
577+
get_buffer()->erase(line_start, line_end);
578+
return true;
579+
}
580+
else {
581+
retval=Gtk::TextView::on_key_press_event(event);
582+
}
583+
538584
// else {
539585
// // If this was a real key press (i.e. not just SHIFT or ALT or similar), emit a
540586
// // signal so that the cell can be scrolled into view if necessary.

web2/cadabra2/source/changelog.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ <h1>Change log</h1>
1818
</p>
1919
<a name="devel"></a>
2020
<h3>github devel branch (2.5.7)</h3>
21+
<ul>
22+
</ul>
23+
24+
<a name="master"></a>
25+
<h3>2.5.8 (released 25-Oct-2024)</h3>
2126
<ul>
2227
<li>Fix handling of spurious backslashes
2328
(<a href="https://github.com/kpeeters/cadabra2/issues/240">#240</a>)
@@ -30,10 +35,16 @@ <h3>github devel branch (2.5.7)</h3>
3035
build.</li>
3136
<li>When an expression is fed through the sympy bridge, make sure to
3237
not remove outer parent relations (so that the expression remains a
33-
sub/superscript if it was one before entering the bridge).</li>
38+
sub/superscript if it was one before entering the bridge).</li>
39+
<li>Fix several bugs with the undo system, and add redo.</li>
40+
<li>Fix split-view mode.</li>
41+
<li>Added optional <tt>partial=False</tt> flag to <tt>zoom</tt> to
42+
enable zooming on exact matches (Daniel).</li>
43+
<li>Add some more standard keybindings (ctrl-k, ctrl-a, ctrl-e) to
44+
input cells.</li>
45+
<li>Generate source tarball asset with microtex included.</li>
3446
</ul>
3547

36-
<a name="master"></a>
3748
<h3>2.5.6 (released 29-Sep-2024)</h3>
3849
<ul>
3950
<li>Windows build is working again, now using MSYS2 because that's the only system that provides binary packages of our dependencies and also still carries gtkmm-3.0. An installer is now auto-generated by the CI on every release.</li>

0 commit comments

Comments
 (0)