Ensure that the supplied filepath is open in a visible window, opening a new split if required. Returns the buffer number of the file and an indication of whether or not a new split was opened. If the supplied filename is already open in a visible window, return just return its buffer numbe
( filepath )
| 950 | |
| 951 | |
| 952 | def _OpenFileInSplitIfNeeded( filepath ): |
| 953 | """Ensure that the supplied filepath is open in a visible window, opening a |
| 954 | new split if required. Returns the buffer number of the file and an indication |
| 955 | of whether or not a new split was opened. |
| 956 | |
| 957 | If the supplied filename is already open in a visible window, return just |
| 958 | return its buffer number. If the supplied file is not visible in a window |
| 959 | in the current tab, opens it in a new vertical split. |
| 960 | |
| 961 | Returns a tuple of ( buffer_num, split_was_opened ) indicating the buffer |
| 962 | number and whether or not this method created a new split. If the user opts |
| 963 | not to open a file, or if opening fails, this method raises RuntimeError, |
| 964 | otherwise, guarantees to return a visible buffer number in buffer_num.""" |
| 965 | |
| 966 | buffer_num = GetBufferNumberForFilename( filepath ) |
| 967 | |
| 968 | # We only apply changes in the current tab page (i.e. "visible" windows). |
| 969 | # Applying changes in tabs does not lead to a better user experience, as the |
| 970 | # quickfix list no longer works as you might expect (doesn't jump into other |
| 971 | # tabs), and the complexity of choosing where to apply edits is significant. |
| 972 | if BufferIsVisible( buffer_num ): |
| 973 | # file is already open and visible, just return that buffer number (and an |
| 974 | # idicator that we *didn't* open a split) |
| 975 | return ( buffer_num, False ) |
| 976 | |
| 977 | # The file is not open in a visible window, so we open it in a split. |
| 978 | # We open the file with a small, fixed height. This means that we don't |
| 979 | # make the current buffer the smallest after a series of splits. |
| 980 | OpenFilename( filepath, { |
| 981 | 'focus': True, |
| 982 | 'fix': True, |
| 983 | 'size': GetIntValue( '&previewheight' ), |
| 984 | } ) |
| 985 | |
| 986 | # OpenFilename returns us to the original cursor location. This is what we |
| 987 | # want, because we don't want to disorientate the user, but we do need to |
| 988 | # know the (now open) buffer number for the filename |
| 989 | buffer_num = GetBufferNumberForFilename( filepath ) |
| 990 | if not BufferIsVisible( buffer_num ): |
| 991 | # This happens, for example, if there is a swap file and the user |
| 992 | # selects the "Quit" or "Abort" options. We just raise an exception to |
| 993 | # make it clear to the user that the abort has left potentially |
| 994 | # partially-applied changes. |
| 995 | raise RuntimeError( |
| 996 | f'Unable to open file: { filepath }\nFixIt/Refactor operation ' |
| 997 | 'aborted prior to completion. Your files have not been ' |
| 998 | 'fully updated. Please use undo commands to revert the ' |
| 999 | 'applied changes.' ) |
| 1000 | |
| 1001 | # We opened this file in a split |
| 1002 | return ( buffer_num, True ) |
| 1003 | |
| 1004 | |
| 1005 | def ReplaceChunks( chunks, silent=False ): |
no test coverage detected