140 Commits

Author SHA1 Message Date
Allan Odgaard
f5832c975f Add missing include statements 2016-06-22 18:31:49 +02:00
Allan Odgaard
371d426c5f Add ‘char const*’ insertion API to ng::buffer_t 2016-06-21 23:23:44 +02:00
Allan Odgaard
4758061719 Do not add final newline to hex dump 2016-06-21 10:51:55 +02:00
Allan Odgaard
2ae0f41a10 Make write_unit_to_fd helper function work with buffer_api_t 2016-06-13 13:01:10 +02:00
Allan Odgaard
029dab73be Make to_xml a member function of buffer_t
We could implement this by using the public scopes member function though this function includes dynamic scopes such as misspelled ranges which would change the current semantics of the to_xml helper function.

It might actually make sense to make this change, but I’m avoiding functional changes while refactoring.
2016-06-13 13:01:10 +02:00
Allan Odgaard
36fedf5bee Change most buffer helper functions to accept buffer_api_t 2016-06-13 13:01:10 +02:00
Allan Odgaard
b59dee8e6d Use semantic assertion 2016-06-13 12:59:31 +02:00
Allan Odgaard
e83fee564c Refactor: use emplace_back(…) instead of push_back(make_pair(…)) 2016-05-28 22:12:46 +02:00
Allan Odgaard
417193e089 Update link dependencies for all targets
Some targets were including headers from frameworks not specified in their link dependencies. For a clean build this could cause an issue because the header was not available at the time of building the target.

The updated link dependencies are also based on what a target’s tests require. Ideally tests would have separate link dependencies, but as we don’t want to maintain this manually, this will have to wait until the build system automatically handles link dependencies.

Currently the commit command uses constants from the CommitWindow framework but should actually not be linked with it. However, the optimizer will strip dead code, so it should not result in much if any difference in the resulting binary and does solve a build dependency issue.
2016-05-07 13:00:55 +02:00
Allan Odgaard
7400fb63ad fixup! Use empty last line from commands working on multiple selections
We only use the last empty line when there are more than a single line break in the string to be inserted.

The use-case here is having multiple carets and then running a command like “echo foo”. Here we receive “foo\n” which is split into (“foo”, “”), so every second caret would get the empty string inserted.
2015-08-27 23:02:17 +02:00
Allan Odgaard
c603b83050 Don’t use “entire document” fallback input with multiple carets 2015-08-27 22:58:56 +02:00
Allan Odgaard
d02421670f Don’t skip sanitizing ranges when input is “entire document”
Incase there are multiple carets, we’ll get multiple “entire documents” ranges.
2015-08-27 22:55:03 +02:00
Allan Odgaard
98206004dc Support fallback units for multiple carets
For example a command that works on selection but falls back to current word will now also work with multiple carets.
2015-07-31 12:37:29 +02:00
Allan Odgaard
755a9e1f7e Look at all carets to decide if there is a selection
Previously we only looked at the last caret, and if this one was not a selection then we would treat the multiple carets (selection ranges) as nothing being selected, and thus, a command replacing the carets, would not leave anything selected.
2015-07-31 12:18:53 +02:00
Allan Odgaard
3047212ed2 Use empty last line from commands working on multiple selections
When pasting or using Filter Through Command with multiple carets, we ignore a potential final empty line, this is because our text will be something like “foo\nbar\n” and we split on the newline, so we end up with (“foo”, “bar”, “”) and if we have more than two carets, then we insert the empty string for every third caret.

For a command though we expect there is a 1:1 between number of carets and newlines in the result, so we should never skip the last element.
2015-07-31 12:01:46 +02:00
Allan Odgaard
58bacfb763 Command with multiple selections would never select output
This now uses the same logic as with a single selection.
2015-07-31 11:48:56 +02:00
Allan Odgaard
d17f509536 Implement a “deselect last” action method
If there are multiple (discontinuous) selections then this action will drop the last one.

If there are multiple carets (with no selections) then this action will drop all but the first caret.
2015-06-12 14:17:06 +02:00
Allan Odgaard
ec37b09faf Use find clipboard when no string is present in macro
This makes it possible to combine the “Use Selection for Find / Replace” with a non-simple find action (e.g. “Replace All”).

If any find options are set (case sensitive, regular expression, etc.) then these will trump the options set for the entry on the find clipboard.
2015-06-12 14:16:50 +02:00
Allan Odgaard
3c49b4fd69 fixup! Support discontinuous selections in command input API
Fixes textmate/bugs#12
2015-03-26 12:13:36 +07:00
Allan Odgaard
491ef65e65 fixup! Support discontinuous selections in command input API 2015-03-23 11:28:19 +07:00
Allan Odgaard
6e5169a9af When command input is discontinuous then split result on LF
Input range i will get the i’th line from the output (module n, with n being total number of output lines).
2015-03-08 16:51:55 +07:00
Allan Odgaard
100c13f3b5 Let command input be LF separated selections when discontinues
This is only when the command input requested is “selection”. In theory it probably should also do this when input is character, word, or line, but in this case, we can end up with overlapping input ranges.
2015-03-08 16:49:19 +07:00
Allan Odgaard
30be46a166 Support discontinuous selections in command input API 2015-03-08 14:21:59 +07:00
Allan Odgaard
40879d5683 Replace sizeofA macro with range-based for loop or std::begin/end 2015-03-05 16:38:09 +07:00
Allan Odgaard
2721b22426 Use recede instead of retreat as the inverse of advance 2014-08-21 16:06:34 +02:00
Allan Odgaard
e81286b0cd Remove unused include 2014-05-16 22:11:28 +07:00
Allan Odgaard
af3f4aaa33 Check result of most CF/CT ‘Create’ functions 2014-05-15 13:17:30 +07:00
Allan Odgaard
39b94e6ac3 Harmonize whitespace and add trailing newline 2014-04-14 14:26:52 +07:00
Allan Odgaard
09ea4b3e46 When document changes (on disk) ensure all selections are valid 2014-04-12 14:13:50 +07:00
Allan Odgaard
2bfd8a8118 Give local function ‘static’ storage 2014-04-12 11:23:07 +07:00
Allan Odgaard
f05f77909e No need to sanitize UTF-8 data in editor_t::paste
We now have the clipboard_t::entry_t ensure that the data is UTF-8.
2014-04-05 14:13:40 +07:00
Allan Odgaard
2b2a20b9b7 Ensure clipboard data is UTF-8 2014-04-05 14:13:40 +07:00
Allan Odgaard
7b182c428b Disable buffer completion when there is no prefix/suffix
We still enable it when a custom completion command provides us with completion candidates. For example user might hit escape in a context where a file name should be inserted, without providing any initial prefix or suffix (as the number of expected candidates is small).
2014-04-05 14:13:40 +07:00
Allan Odgaard
db13d4c1f9 Use std::string::back() instead of operator[] with size()-1 2014-03-31 08:27:18 +07:00
Allan Odgaard
d985a83845 Use runner_t::wait_for_command instead of runner_t::wait(true)
The latter API has been removed.
2014-03-29 09:57:09 +07:00
Allan Odgaard
935da75a43 Use new path::temp API to set initial content 2014-03-28 19:31:15 +07:00
Allan Odgaard
69504292e5 Better job of moving caret/preserving selection for “toggle case”
Previously we would set a mark, mutate the buffer, and then restore selection based on how the mark was moved.

When a mutation was changing the buffer to its existing value (e.g. toggling case of a space character) then the buffer would effectively ignore the mutation, and the mark would not be properly updated, meaning for “toggle case of character” the caret would not be moved forward.

Additionally we previously always moved to the end of a mutation, even if it was done on a user selection. We now only move to the end if the user didn’t select anything (but ran the mutation on an implicitly selected unit, like a word). The “toggle case of word” action is affected by this.
2014-03-25 12:19:58 +07:00
Allan Odgaard
d4faf3bef8 Code indicated we were preserving selection for kChangeCaseOfWord 2014-03-23 22:47:16 +07:00
Allan Odgaard
d7660bd89e Detect first loop iteration using std::exchange “idiom” 2014-03-23 22:47:15 +07:00
Allan Odgaard
e7e1aed59c Inserting “after input” is always lower/right corner for columns
For example selecting a column of numbers and selecting “Add Numbers in Selection” will now always insert the result at a logical position rather than on the defined end points of the selection.
2014-03-10 12:40:18 +07:00
Allan Odgaard
c7ae7d1337 Add test for snippets with overlapping fields
See 4e1cdb4c9e for details.
2014-03-07 00:10:35 +07:00
Allan Odgaard
c2397484b8 Use C++11 for loop
Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
2014-03-03 10:34:13 +07:00
Allan Odgaard
be92d71c46 Allow disabling indent corrections when typing on empty lines
This is generally desired when the indent of a new line does not (necessarily) depend on lines above it, but where we otherwise do want indent corrections, e.g. HTML.
2014-03-02 20:06:31 +07:00
Allan Odgaard
4e1cdb4c9e Snippets with overlapping fields could cause multiple carets
For example in ruby inserting ‘env⇥’, deleting the initially selected letter, and typing B or S, would insert an additional caret (it was actually inserted in the previous step, but not visible since it was overlapping the existing caret).

The API lack proper support for returning the new caret range so we are using a heuristic to figure out which of the returned ranges correspond to our caret. Ideally the API would be updated.
2014-02-26 08:29:42 +07:00
Allan Odgaard
56a906a0ac Use temporary pasteboards when replaying macros
This applies to search, replace, and (unless disabled) regular pasteboard.
2014-02-20 22:22:55 +07:00
Allan Odgaard
aec82de6e2 Implement kReplace / kReplaceAndFind actions
These are used when replaying macros.
2014-02-20 22:09:36 +07:00
Allan Odgaard
17dca05dba Let editor_t remember (regexp) captures from editor_t::find 2014-02-20 22:09:36 +07:00
Allan Odgaard
aff813203b Find macro actions now populate the search/replace pasteboard
This should be consistent with TextMate 1.x and is required for the replace actions.
2014-02-20 22:09:36 +07:00
Allan Odgaard
16c7679c0a Use ng::word_at for what to complete
This way we won’t try to complete whitespace.
2014-02-12 20:08:41 +07:00
Allan Odgaard
3b760492a8 Do not set TM_CURRENT_WORD if caret is surrounded by whitespace
This is consistent with “word” as input for commands.
2014-02-11 20:56:38 +07:00