This function adjusts the candidate insertion text to take into account the text that's currently in front of the cursor. For instance ('|' represents the cursor): 1. Buffer state: 'foo.|bar' 2. A completion candidate of 'zoobar' is shown and the user selects it. 3. Buffer state: 'f
( candidates )
| 88 | |
| 89 | |
| 90 | def AdjustCandidateInsertionText( candidates ): |
| 91 | """This function adjusts the candidate insertion text to take into account the |
| 92 | text that's currently in front of the cursor. |
| 93 | |
| 94 | For instance ('|' represents the cursor): |
| 95 | 1. Buffer state: 'foo.|bar' |
| 96 | 2. A completion candidate of 'zoobar' is shown and the user selects it. |
| 97 | 3. Buffer state: 'foo.zoobar|bar' instead of 'foo.zoo|bar' which is what the |
| 98 | user wanted. |
| 99 | |
| 100 | This function changes candidates to resolve that issue. |
| 101 | |
| 102 | It could be argued that the user actually wants the final buffer state to be |
| 103 | 'foo.zoobar|' (the cursor at the end), but that would be much more difficult |
| 104 | to implement and is probably not worth doing. |
| 105 | """ |
| 106 | |
| 107 | def NewCandidateInsertionText( to_insert, text_after_cursor ): |
| 108 | overlap_len = OverlapLength( to_insert, text_after_cursor ) |
| 109 | if overlap_len: |
| 110 | return to_insert[ :-overlap_len ] |
| 111 | return to_insert |
| 112 | |
| 113 | text_after_cursor = vimsupport.TextAfterCursor() |
| 114 | if not text_after_cursor: |
| 115 | return candidates |
| 116 | |
| 117 | new_candidates = [] |
| 118 | for candidate in candidates: |
| 119 | new_candidate = candidate.copy() |
| 120 | |
| 121 | if not new_candidate.get( 'abbr' ): |
| 122 | new_candidate[ 'abbr' ] = new_candidate[ 'word' ] |
| 123 | |
| 124 | new_candidate[ 'word' ] = NewCandidateInsertionText( |
| 125 | new_candidate[ 'word' ], |
| 126 | text_after_cursor ) |
| 127 | |
| 128 | new_candidates.append( new_candidate ) |
| 129 | return new_candidates |
| 130 | |
| 131 | |
| 132 | def OverlapLength( left_string, right_string ): |
nothing calls this directly
no test coverage detected