Skip to content

Commit

Permalink
No longer using PyAction.getDelimiter when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Aug 27, 2024
1 parent 180c308 commit 1108edb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +79,7 @@ public List<ICompletionProposalHandle> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public List<ICompletionProposalHandle> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,7 +94,7 @@ public List<ICompletionProposalHandle> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -281,14 +281,14 @@ private IContainer getContainer() {

/**
* The <code>PasteAction</code> implementation of this
* <code>SelectionListenerAction</code> method enables this action if
* <code>SelectionListenerAction</code> 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) {
Expand Down Expand Up @@ -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<? extends IResource> selectedResources = getSelectedResources();
if (selectedResources.size() > 1) {
Expand Down

0 comments on commit 1108edb

Please sign in to comment.