textbringer 5 → 6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee5d500943649b27e9bebc067bb17e9192ca313fd653d272a6a4d0a2dacae838
4
- data.tar.gz: 242eb5276649e97ff5677f3bd3a85e59b2c245818350741cf362429c2e7202a8
3
+ metadata.gz: 1a4e9151c1c0eb5b77a04aa772527cbab44782e161bdec0885d262d3af625fce
4
+ data.tar.gz: 7e32c6f85241240b08944de42b12174bd8e8f41568e4b65f24696355b5bd72e0
5
5
  SHA512:
6
- metadata.gz: 927d28e674b1824f8e297599e6d34946625c3a28f677540953540798d89b444fef29d4e55eb8a5b0dfc51531d069a6da078f69f85d45a9a3a8acef84a8be7fd0
7
- data.tar.gz: 8f2b663c0b7bbf58d1d8356b8d921f8218534c47b03bcde3031ebaa5f76568d473f67418bf6277d22800be82ea0bbdd1503eca411e3d8a1c715848679fe8dc73
6
+ metadata.gz: a49c66d31e61433c3755373cdc469a84c1c7c4f43391687287e5daa23e96d0a082ed82aebea89b0281982fdd16972eda67ff140379142242df455b6a22753166
7
+ data.tar.gz: 62df368e736bd9e7c31772cf75e6bb5f64781b9768d49352da87f7bd3e2eb91c2266dd2dd71660940024c99c0da8a89e4116cac04146de4a048bf8d2b6753e7d
@@ -1759,6 +1759,8 @@ module Textbringer
1759
1759
  end
1760
1760
 
1761
1761
  class InsertAction < UndoableAction
1762
+ attr_reader :string
1763
+
1762
1764
  def initialize(buffer, location, string)
1763
1765
  super(buffer, location)
1764
1766
  @string = string
@@ -1785,6 +1787,8 @@ module Textbringer
1785
1787
  end
1786
1788
 
1787
1789
  class DeleteAction < UndoableAction
1790
+ attr_reader :string
1791
+
1788
1792
  def initialize(buffer, location, insert_location, string)
1789
1793
  super(buffer, location)
1790
1794
  @insert_location = insert_location
@@ -65,7 +65,8 @@ module Textbringer
65
65
  end
66
66
 
67
67
  def command_help(cmd)
68
- s = format("%s:%d\n", *cmd.block.source_location)
68
+ file, line = *cmd.block.source_location
69
+ s = format("%s:%d\n", file, line)
69
70
  s << "-" * (Window.columns - 2) + "\n"
70
71
  s << "#{cmd.name}"
71
72
  if !cmd.block.parameters.empty?
@@ -1,4 +1,27 @@
1
1
  module Textbringer
2
+ using Module.new {
3
+ refine Buffer do
4
+ def merge_overwrite_action
5
+ if @undoing || @undo_stack.size < 2 ||
6
+ !@undo_stack[-1].is_a?(DeleteAction) ||
7
+ !@undo_stack[-2].is_a?(InsertAction)
8
+ return
9
+ end
10
+ delete_action = @undo_stack.pop
11
+ insert_action = @undo_stack.pop
12
+ action = @undo_stack.last
13
+ if action.is_a?(OverwriteAction)
14
+ action.merge(insert_action.string, delete_action.string)
15
+ @redo_stack.clear
16
+ else
17
+ new_action = OverwriteAction.new(self, insert_action.location,
18
+ insert_action.string, delete_action.string)
19
+ push_undo(new_action)
20
+ end
21
+ end
22
+ end
23
+ }
24
+
2
25
  class OverwriteMode < MinorMode
3
26
  self.mode_name = "Ovwrt"
4
27
 
@@ -14,6 +37,7 @@ module Textbringer
14
37
  buffer.delete_region(pos, buffer.point)
15
38
  end
16
39
  end
40
+ buffer.merge_overwrite_action
17
41
  }
18
42
 
19
43
  def enable
@@ -24,4 +48,36 @@ module Textbringer
24
48
  remove_hook(:post_self_insert_hook, POST_INSERT_HOOK, local: true)
25
49
  end
26
50
  end
51
+
52
+ class OverwriteAction < UndoableAction
53
+ def initialize(buffer, location, inserted_string, deleted_string)
54
+ super(buffer, location)
55
+ @inserted_string = inserted_string
56
+ @deleted_string = deleted_string
57
+ @copied = false
58
+ end
59
+
60
+ def undo
61
+ @buffer.goto_char(@location)
62
+ @buffer.delete_region(@location, @location + @inserted_string.bytesize)
63
+ @buffer.insert(@deleted_string)
64
+ @buffer.goto_char(@location)
65
+ end
66
+
67
+ def redo
68
+ @buffer.goto_char(@location)
69
+ @buffer.delete_region(@location, @location + @deleted_string.bytesize)
70
+ @buffer.insert(@inserted_string)
71
+ end
72
+
73
+ def merge(inserted_string, deleted_string)
74
+ unless @copied
75
+ @inserted_string = @inserted_string.dup
76
+ @deleted_string = @deleted_string.dup
77
+ @copied = true
78
+ end
79
+ @inserted_string.concat(inserted_string)
80
+ @deleted_string.concat(deleted_string)
81
+ end
82
+ end
27
83
  end
@@ -1,3 +1,3 @@
1
1
  module Textbringer
2
- VERSION = "5"
2
+ VERSION = "6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textbringer
3
3
  version: !ruby/object:Gem::Version
4
- version: '5'
4
+ version: '6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda