From 1108edbe13f76fd4d9cb4768b0eb052e1a0e9717 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Tue, 27 Aug 2024 07:51:02 -0300 Subject: [PATCH] No longer using PyAction.getDelimiter when possible. --- .../pydev/editor/actions/PyBackspace.java | 2 +- .../proposals/PyConsoleCompletion.java | 4 +-- .../docstrings/AssistDocString.java | 3 +-- .../heuristics/AssistImport.java | 2 +- .../heuristics/AssistSurroundWith.java | 3 +-- .../navigator/actions/copied/PasteAction.java | 26 +++++++++---------- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/actions/PyBackspace.java b/plugins/org.python.pydev/src/org/python/pydev/editor/actions/PyBackspace.java index 6cd63b692b..a5100cf44b 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/actions/PyBackspace.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/actions/PyBackspace.java @@ -255,7 +255,7 @@ private void eraseLineDelimiter(PySelection ps) throws BadLocationException { ICoreTextSelection textSelection = ps.getTextSelection(); - int length = getDelimiter(ps.getDoc()).length(); + int length = ps.getEndLineDelim().length(); int offset = textSelection.getOffset() - length; //System.out.println("Replacing offset: "+(offset) +" lenght: "+ diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/PyConsoleCompletion.java b/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/PyConsoleCompletion.java index 1b0326d680..43b0b99861 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/PyConsoleCompletion.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/PyConsoleCompletion.java @@ -11,9 +11,9 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.swt.graphics.Point; +import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.interactive_console.IScriptConsoleViewer; import org.python.pydev.core.log.Log; -import org.python.pydev.editor.actions.PyAction; /** * Extends the basic completion proposal to add a line with an import in the console. @@ -78,7 +78,7 @@ public void apply(IDocument document, char trigger, int stateMask, int offset, I document.replace(commandLineOffset, document.getLength() - commandLineOffset, ""); boolean addImport = realImportRep.length() > 0; - String delimiter = PyAction.getDelimiter(document); + String delimiter = PySelection.getDelimiter(document); //now, add the import if that should be done... diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/docstrings/AssistDocString.java b/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/docstrings/AssistDocString.java index ac4cbf4a4b..14be2891cd 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/docstrings/AssistDocString.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/docstrings/AssistDocString.java @@ -31,7 +31,6 @@ import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.docutils.PySelection.DocstringInfo; import org.python.pydev.core.proposals.CompletionProposalFactory; -import org.python.pydev.editor.actions.PyAction; import org.python.pydev.editor.correctionassist.IAssistProps; import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle; import org.python.pydev.shared_core.code_completion.IPyCompletionProposal; @@ -80,7 +79,7 @@ public List getProps(PySelection ps, IImageCache imag // Calculate only the initial part of the docstring here (everything else should be lazily computed on apply). String initial = PySelection.getIndentationFromLine(ps.getCursorLineContents()); - String delimiter = PyAction.getDelimiter(ps.getDoc()); + String delimiter = ps.getEndLineDelim(); String indentation = edit != null ? edit.getIndentPrefs().getIndentationString() : DefaultIndentPrefs.get( nature).getIndentationString(); diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistImport.java b/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistImport.java index 6a0c680fc0..91ef3fbf22 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistImport.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistImport.java @@ -48,7 +48,7 @@ public List getProps(PySelection ps, IImageCache imag return l; } - String delimiter = PyAction.getDelimiter(ps.getDoc()); + String delimiter = ps.getEndLineDelim(); boolean isFuture = PySelection.isFutureImportLine(sel.trim()); int lineToMoveImport = ps.getLineAvailableForImport(isFuture); diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistSurroundWith.java b/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistSurroundWith.java index da927c1119..ab6bcbaa07 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistSurroundWith.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/correctionassist/heuristics/AssistSurroundWith.java @@ -28,7 +28,6 @@ import org.python.pydev.core.autoedit.DefaultIndentPrefs; import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.proposals.CompletionProposalFactory; -import org.python.pydev.editor.actions.PyAction; import org.python.pydev.editor.codecompletion.PyTemplateProposal; import org.python.pydev.editor.correctionassist.IAssistProps; import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle; @@ -95,7 +94,7 @@ public List getProps(PySelection ps, IImageCache imag } //delimiter to use - String delimiter = PyAction.getDelimiter(ps.getDoc()); + String delimiter = ps.getEndLineDelim(); //get the 1st char (determines indent) FastStringBuffer startIndentBuffer = new FastStringBuffer(firstCharPosition + 1); diff --git a/plugins/org.python.pydev/src_navigator/org/python/pydev/navigator/actions/copied/PasteAction.java b/plugins/org.python.pydev/src_navigator/org/python/pydev/navigator/actions/copied/PasteAction.java index ddba023597..9fec68e8cf 100644 --- a/plugins/org.python.pydev/src_navigator/org/python/pydev/navigator/actions/copied/PasteAction.java +++ b/plugins/org.python.pydev/src_navigator/org/python/pydev/navigator/actions/copied/PasteAction.java @@ -38,13 +38,13 @@ import org.eclipse.ui.ide.IDE; import org.eclipse.ui.part.ResourceTransfer; import org.python.pydev.ast.codecompletion.revisited.PythonPathHelper; +import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.log.Log; -import org.python.pydev.editor.actions.PyAction; import org.python.pydev.shared_core.string.StringUtils; /** * Copied to extend. - * + * * @since 2.0 */ public abstract class PasteAction extends SelectionListenerAction { @@ -85,7 +85,7 @@ public PasteAction(Shell shell, Clipboard clipboard) { /** * Returns the actual target of the paste action. Returns null * if no valid target is selected. - * + * * @return the actual target of the paste action */ private IResource getTarget() { @@ -109,9 +109,9 @@ private IResource getTarget() { /** * Returns whether any of the given resources are linked resources. - * + * * @param resources resource to check for linked type. may be null - * @return true=one or more resources are linked. false=none of the + * @return true=one or more resources are linked. false=none of the * resources are linked */ private boolean isLinked(IResource[] resources) { @@ -176,7 +176,7 @@ public void run() { if (name == null) { return; } - String delimiter = PyAction.getDelimiter(new Document()); + String delimiter = PySelection.getDelimiter(new Document()); if (delimiter != null) { contents = StringUtils.replaceNewLines(contents, delimiter); } @@ -281,14 +281,14 @@ private IContainer getContainer() { /** * The PasteAction implementation of this - * SelectionListenerAction method enables this action if + * SelectionListenerAction method enables this action if * a resource compatible with what is on the clipboard is selected. - * + * * -Clipboard must have IResource or java.io.File * -Projects can always be pasted if they are open * -Workspace folder may not be copied into itself - * -Files and folders may be pasted to a single selected folder in open - * project or multiple selected files in the same folder + * -Files and folders may be pasted to a single selected folder in open + * project or multiple selected files in the same folder */ @Override protected boolean updateSelection(IStructuredSelection selection) { @@ -325,13 +325,13 @@ public void run() { } IResource targetResource = getTarget(); - // targetResource is null if no valid target is selected (e.g., open project) - // or selection is empty + // targetResource is null if no valid target is selected (e.g., open project) + // or selection is empty if (targetResource == null) { return false; } - // can paste files and folders to a single selection (file, folder, + // can paste files and folders to a single selection (file, folder, // open project) or multiple file selection with the same parent List selectedResources = getSelectedResources(); if (selectedResources.size() > 1) {