@@ -1700,9 +1700,10 @@ CUSTOM_DOC("Reopen the current buffer from the hard drive.")
1700
1700
1701
1701
// //////////////////////////////
1702
1702
1703
- internal i32
1703
+ internal i64
1704
1704
record_get_new_cursor_position_undo (Application_Links *app, Buffer_ID buffer_id, History_Record_Index index, Record_Info record){
1705
- i32 new_edit_position = 0 ;
1705
+ i64 new_edit_position = record.pos_before_edit ;
1706
+ #if 0
1706
1707
switch (record.kind){
1707
1708
default:
1708
1709
case RecordKind_Single:
@@ -1715,16 +1716,17 @@ record_get_new_cursor_position_undo(Application_Links *app, Buffer_ID buffer_id,
1715
1716
new_edit_position = (i32)(sub_record.single_first + sub_record.single_string_backward.size);
1716
1717
}break;
1717
1718
}
1719
+ #endif
1718
1720
return (new_edit_position);
1719
1721
}
1720
1722
1721
- internal i32
1723
+ internal i64
1722
1724
record_get_new_cursor_position_undo (Application_Links *app, Buffer_ID buffer_id, History_Record_Index index){
1723
1725
Record_Info record = buffer_history_get_record_info (app, buffer_id, index );
1724
1726
return (record_get_new_cursor_position_undo (app, buffer_id, index , record));
1725
1727
}
1726
1728
1727
- internal i32
1729
+ internal i64
1728
1730
record_get_new_cursor_position_redo (Application_Links *app, Buffer_ID buffer_id, History_Record_Index index, Record_Info record){
1729
1731
i64 new_edit_position = 0 ;
1730
1732
switch (record.kind ){
@@ -1742,21 +1744,80 @@ record_get_new_cursor_position_redo(Application_Links *app, Buffer_ID buffer_id,
1742
1744
return ((i32)(new_edit_position));
1743
1745
}
1744
1746
1745
- internal i32
1747
+ internal i64
1746
1748
record_get_new_cursor_position_redo (Application_Links *app, Buffer_ID buffer_id, History_Record_Index index){
1747
1749
Record_Info record = buffer_history_get_record_info (app, buffer_id, index );
1748
1750
return (record_get_new_cursor_position_redo (app, buffer_id, index , record));
1749
1751
}
1750
1752
1753
+ function void
1754
+ undo__fade_finish (Application_Links *app, Fade_Range *range){
1755
+ Buffer_ID buffer = range->buffer_id ;
1756
+ History_Record_Index current = buffer_history_get_current_state_index (app, buffer);
1757
+ if (current > 0 ){
1758
+ buffer_history_set_current_state_index (app, buffer, current - 1 );
1759
+ }
1760
+ }
1761
+
1762
+ function void
1763
+ undo__flush_fades (Application_Links *app, Buffer_ID buffer){
1764
+ Fade_Range **prev_next = &buffer_fade_ranges.first ;
1765
+ for (Fade_Range *node = buffer_fade_ranges.first , *next = 0 ;
1766
+ node != 0 ;
1767
+ node = next){
1768
+ next = node->next ;
1769
+ if (node->buffer_id == buffer &&
1770
+ node->finish_call == undo__fade_finish){
1771
+ undo__fade_finish (app, node);
1772
+ *prev_next = next;
1773
+ free_fade_range (node);
1774
+ buffer_fade_ranges.count -= 1 ;
1775
+ }
1776
+ else {
1777
+ prev_next = &node->next ;
1778
+ buffer_fade_ranges.last = node;
1779
+ }
1780
+ }
1781
+ }
1782
+
1751
1783
CUSTOM_COMMAND_SIG (undo)
1752
1784
CUSTOM_DOC(" Advances backwards through the undo history of the current buffer." )
1753
1785
{
1754
1786
View_ID view = get_active_view (app, Access_ReadWriteVisible);
1755
1787
Buffer_ID buffer = view_get_buffer (app, view, Access_ReadWriteVisible);
1788
+ undo__flush_fades (app, buffer);
1789
+
1756
1790
History_Record_Index current = buffer_history_get_current_state_index (app, buffer);
1757
1791
if (current > 0 ){
1758
- i32 new_position = record_get_new_cursor_position_undo (app, buffer, current);
1759
- buffer_history_set_current_state_index (app, buffer, current - 1 );
1792
+ Record_Info record = buffer_history_get_record_info (app, buffer, current);
1793
+
1794
+ b32 do_immedite_undo = true ;
1795
+ f32 undo_fade_time = 0 .33f ;
1796
+ if (undo_fade_time > 0 .f &&
1797
+ record.kind == RecordKind_Single &&
1798
+ record.single_string_backward .size == 0 ){
1799
+ b32 has_hard_character = false ;
1800
+ for (u64 i = 0 ; i < record.single_string_forward .size ; i += 1 ){
1801
+ if (!character_is_whitespace (record.single_string_forward .str [i])){
1802
+ has_hard_character = true ;
1803
+ break ;
1804
+ }
1805
+ }
1806
+ if (has_hard_character){
1807
+ Range_i64 range = Ii64_size (record.single_first , record.single_string_forward .size );
1808
+ ARGB_Color color = fcolor_resolve (fcolor_id (defcolor_undo)) & 0xFFFFFF ;
1809
+ Fade_Range *fade = buffer_post_fade (app, buffer, undo_fade_time, range, color);
1810
+ fade->negate_fade_direction = true ;
1811
+ fade->finish_call = undo__fade_finish;
1812
+ do_immedite_undo = false ;
1813
+ }
1814
+ }
1815
+
1816
+ if (do_immedite_undo){
1817
+ buffer_history_set_current_state_index (app, buffer, current - 1 );
1818
+ }
1819
+
1820
+ i64 new_position = record_get_new_cursor_position_undo (app, buffer, current, record);
1760
1821
view_set_cursor_and_preferred_x (app, view, seek_pos (new_position));
1761
1822
}
1762
1823
}
@@ -1769,7 +1830,7 @@ CUSTOM_DOC("Advances forwards through the undo history of the current buffer.")
1769
1830
History_Record_Index current = buffer_history_get_current_state_index (app, buffer);
1770
1831
History_Record_Index max_index = buffer_history_get_max_record_index (app, buffer);
1771
1832
if (current < max_index){
1772
- i32 new_position = record_get_new_cursor_position_redo (app, buffer, current + 1 );
1833
+ i64 new_position = record_get_new_cursor_position_redo (app, buffer, current + 1 );
1773
1834
buffer_history_set_current_state_index (app, buffer, current + 1 );
1774
1835
view_set_cursor_and_preferred_x (app, view, seek_pos (new_position));
1775
1836
}
@@ -1806,15 +1867,15 @@ CUSTOM_DOC("Advances backward through the undo history in the buffer containing
1806
1867
}
1807
1868
1808
1869
Buffer_ID *match_buffers = push_array (scratch, Buffer_ID, match_count);
1809
- i32 *new_positions = push_array (scratch, i32 , match_count);
1870
+ i64 *new_positions = push_array (scratch, i64 , match_count);
1810
1871
match_count = 0 ;
1811
1872
1812
1873
if (highest_edit_number != -1 ){
1813
1874
for (Buffer_ID buffer = first_buffer_match;
1814
1875
buffer != 0 ;
1815
1876
buffer = get_buffer_next (app, buffer, Access_Always)){
1816
1877
b32 did_match = false ;
1817
- i32 new_edit_position = 0 ;
1878
+ i64 new_edit_position = 0 ;
1818
1879
for (;;){
1819
1880
History_Record_Index index = buffer_history_get_current_state_index (app, buffer);
1820
1881
if (index > 0 ){
@@ -1879,15 +1940,15 @@ CUSTOM_DOC("Advances forward through the undo history in the buffer containing t
1879
1940
}
1880
1941
1881
1942
Buffer_ID *match_buffers = push_array (scratch, Buffer_ID, match_count);
1882
- i32 *new_positions = push_array (scratch, i32 , match_count);
1943
+ i64 *new_positions = push_array (scratch, i64 , match_count);
1883
1944
match_count = 0 ;
1884
1945
1885
1946
if (lowest_edit_number != -1 ){
1886
1947
for (Buffer_ID buffer = first_buffer_match;
1887
1948
buffer != 0 ;
1888
1949
buffer = get_buffer_next (app, buffer, Access_Always)){
1889
1950
b32 did_match = false ;
1890
- i32 new_edit_position = 0 ;
1951
+ i64 new_edit_position = 0 ;
1891
1952
History_Record_Index max_index = buffer_history_get_max_record_index (app, buffer);
1892
1953
for (;;){
1893
1954
History_Record_Index index = buffer_history_get_current_state_index (app, buffer);
0 commit comments