68 Commits

Author SHA1 Message Date
Allan Odgaard
8f685ff25c Use std::clamp instead of oak::cap (C++17) 2019-08-01 10:23:55 +02:00
Allan Odgaard
eb4e0bfcd0 Update tests to reflect how the code works
The “matching pair” move behavior was changed in 7f99c4cbc7
2019-07-16 14:27:28 +02:00
Ronald Wampler
4aed5b4d9b Add virtual destructors for buffer_api_t and layout_movement_t
This suppresses the warning `Wdelete-non-virtual-dtor`. AFAICT, the existing usage isn't necessarily wrong (i.e., we don't delete through them) so another way to resolve the warning is to mark the classes that inherit from them, e.g., `buffer_t` as `final`.
2018-10-12 19:37:41 +02:00
Allan Odgaard
7f99c4cbc7 Change definition of moving to begin/end of highlight characters
Previously if caret was before an “open” character or after a “close” character, example:

    if‸(true)‸

Then we would move to the matching character, rather than the begin/end character of the “parent” block.

We no longer move to the matching character but instead go straight to the begin/end of parent block.
2018-10-03 20:11:20 +02:00
mathbunnyru
440414f96c Use nullptr in all C++ files instead of NULL
This brings us a bit of extra type safety, for example where an integer is expected, nullptr should be disallowed by the compiler (unlike NULL).
2016-10-22 21:40:14 +07:00
mathbunnyru
284b5a3896 Slight perfomance improvements 2016-10-18 23:06:48 +02:00
Allan Odgaard
2feb4a497a Use crash_reporter_info_t’s convenience constructor
Also change most ‘crashInfo’ variable names to just ‘info’ to be consistent.
2016-10-07 22:14:33 +02:00
Allan Odgaard
3d39c03ced Remove layout dependency from editor framework 2016-10-01 09:03:22 +02:00
Allan Odgaard
a1c5ff8b17 Fix implementation of range_t::empty
A range with an undefined end point would be reported as empty.
2016-08-25 09:41:21 +02:00
Allan Odgaard
b4f421119d Indented line movement now produce multiple carets for column selections 2016-08-17 15:23:05 +02:00
Allan Odgaard
c947ca6659 Add crash report debug info 2016-08-04 00:34:53 +02:00
Allan Odgaard
33aec21dcb Provide buffer_t visitor with offset and a way to stop the visit
If the lambda stops the visit then buffer_t::visit_data will return true, otherwise it returns false.
2016-06-22 23:22:47 +02:00
Allan Odgaard
a340811771 Allow access to buffer_t’s raw storage via the visitor interface
Previously this was done by exposing iterators but for this to go into the abstract base class we sort of need abstract iterators and that is too complex and visitor interface is sufficient for our single use case.
2016-06-13 13:02:49 +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
59c5b0023d Refactor: Consistent buffer_t parameter name (buf → buffer) 2016-06-13 12:59:31 +02:00
Adam Strzelecki
aba1eb42ac Exclude given scopes when extending selection
This introduces new scope setting - excludeFromParagraphSelection, that
prevents extending selection to some scopes, eg. on comment.line.

Previously when reformatting paragraph comment lines were selected as paragraph
lines, this have led to mixing comment content into reformatted paragraph
content breaking the syntax of reformatted code, eg.:

  some very long ... line of text
  # some comment
  some other long ... line of text

As an effect we got:

  some very long ...
  ... text # some comment some other ...
  ... line of text

The problem described above was especially visible when using ⌃Q to Reformat
block of Git commit message, when below of the typed text there was a Git
default comment. Also this problem could be noticeable by authors using LaTeX.

This change checks whether a candidate line scope for paragraph extension has a
excludeFromParagraphSelection set to true and breaks upon such line, eg.
comment line.

Doing Select Paragraph ⌃⌥P again will select the comment as well.
2016-06-02 21:07:43 +02:00
Brian T. Kelley
2dd825515e Double Click to Select Typing Pairs
TextMate highlights certain character pairs (e.g. { }) when the caret passes over either of the characters. It can be useful to double click to select the text in between and including the character pairs for deleting code, copying code, for visually differentiating the affected code, etc. Add a select_unit_type, kSelectionExtendToWordOrTypingPair, to select the inclusive bounds of a typing pair if a match is found, or otherwise select a word as normal.

This patch is free and released into the public domain.
2016-04-15 00:25:24 +07:00
Allan Odgaard
c56bb0c9f1 Double-tapping shift disables “freehanded mode” for single caret 2015-06-25 23:01:58 +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
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
db13d4c1f9 Use std::string::back() instead of operator[] with size()-1 2014-03-31 08:27:18 +07:00
Allan Odgaard
cefb8cb2db Simplify sub-word movement tests 2014-03-25 12:19:58 +07:00
Allan Odgaard
527668683c Include numbers as a group for sub-word movement 2014-03-25 12:19:58 +07:00
Allan Odgaard
15025edbcc Set “color” to true if range is untouched by ‘extend_if_empty’ 2014-03-25 12:19:57 +07:00
Allan Odgaard
62645601f5 Introduce range_t::color field for somewhat arbitrary use
Also do a better job of preserving the “unanchored” property of a range.
2014-03-25 12:19:57 +07:00
Allan Odgaard
54d7f4bbeb Split regexp used for sub-word movement into multiple lines 2014-03-23 22:47:15 +07:00
Allan Odgaard
9397335400 Add tests for sub-word movement 2014-03-23 22:47:15 +07:00
Allan Odgaard
af0e6cc643 Change decltype(mapVariable)::value_type → auto (C++14) 2014-03-16 18:06:03 +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
9cfd98446f The ng::word_at function would not extend selection to full word
This would affect the buffer completion, which would work sub-optimally when selecting part of the word for replacement.
2014-02-14 00:40:54 +07:00
Allan Odgaard
da31c2d11a Introduce ng::word_at (refactoring) 2014-02-11 20:55:01 +07:00
Allan Odgaard
286a92c792 Select word at EOL with trailing whitespace was a no-op 2014-02-01 21:34:34 +07:00
Allan Odgaard
16f7109656 Fix swapped freehanded left/right constants
In practice move() isn’t called with a freehanded left/right constant so the incorrect placement wasn’t causing an issue.
2014-01-13 11:16:11 +07:00
Allan Odgaard
7b0e92376c Add “wordCharacters” as a scoped setting
Set this to a string of which characters should be added to the set of word characters.
2013-10-30 21:16:20 +01:00
Allan Odgaard
1c308c810d Use map::emplace instead of inserting std::pair (C++11) 2013-09-05 20:59:11 +02:00
Allan Odgaard
b52b13329e Call scope_t::empty instead of using an operator bool cast 2013-08-30 12:30:34 +02:00
Allan Odgaard
69316d4da1 Don’t call scope_t::push_scope with empty scope attributes
Previously would be called with an empty string.
2013-08-30 12:30:33 +02:00
Allan Odgaard
d93b20d571 Use new scope_t API 2013-08-28 00:23:08 +02:00
Allan Odgaard
057096af5b Rename API to make searching easier
Using generic names like ‘append’ is not good when analyzing code for potential refactoring.
2013-08-27 15:30:09 +02:00
Allan Odgaard
bf1e92b865 Do not use global constructors for fixtures 2013-08-16 22:40:08 +02:00
Allan Odgaard
7e1242b26f Improve handling of zero-width search results
Previously when using find next/previous and the caret was already on a zero-width match position, TextMate would stay on this match.
2013-07-31 20:58:10 +02:00
Allan Odgaard
267471d7bb Account for multi-byte characters when moving search position
Fixes #1070
2013-07-31 20:24:16 +02:00
Allan Odgaard
0c59a10aa1 Update testing system for selection framework 2013-07-26 13:53:58 +02:00
Allan Odgaard
d40faab873 Improve ng::find semantics
When no matches are found then we search the selected range for a match and use that.

Also add a “did wrap” out parameter to the API.
2013-07-23 21:15:35 +02:00
Allan Odgaard
25ed8b4e62 Highlight pairs can now be regular expressions
These settings are also consulted for “pair movement”, i.e. ⌃↓/⌃↑ and ⇧⌘B, so by using regular expressions we can match begin/end tags and navigate between these.
2013-07-21 13:25:30 +02:00
Allan Odgaard
920d75b2e7 Remove warning from regexp test
The problem is with the underlying library and has been reported to its issue tracker.
2013-07-21 13:25:30 +02:00
Allan Odgaard
32e18b2697 Improve code to find “paired character ranges”
The algorithm now handle overlapping character ranges like: ‘(f{o)o}’ and unpaired characters surrounded by character pairs.

This is for selecting (⇧⌘B) and moving to the begin or end of the range (⌃↓/⌃↑).
2013-07-21 13:25:28 +02:00
Allan Odgaard
ad02f214ac Improve readability of brace movement tests 2013-07-21 13:25:27 +02:00
Allan Odgaard
4480684421 Prevent (some forms of) overlapping selections 2013-06-25 19:36:32 +02:00